NoSQL Zone is brought to you in partnership with:

Software developer specializing in MongoDB, Python, Tornado, and Javascript, with particular interests in real-time web and new tools that get the job done with grace and alacrity. A. Jesse Jiryu is a DZone MVB and is not an employee of DZone and has posted 69 posts at DZone. You can read more from them at their website. View Full User Profile

PyMongo 2.6.1 Released With Refleak Fix

09.05.2013
| 1126 views |
  • submit to reddit

Leak

Bernie Hackett and I released PyMongo 2.6.1 yesterday. This version fixes a bug in PyMongo 2.6, a reference-count leak in insert() that caused memory to grow slowly without bound. Please upgrade immediately.

Sorry about the bug. We introduced it into PyMongo's C code while implementing auto-splitting for very large batch inserts, but it affects all calls to insert regardless of size. If you use PyMongo without building its C extensions, for example if you're on PyPy or Jython, the bug does not affect you.

The new auto-splitting code serializes a sequence of documents as BSON until its buffer reaches 48MB, at which point it calls, from C, the Python method _send_message to fire off the batch to the server. Unfortunately, the C code didn't dereference the server response from _send_message. The response is small, something like this:

{'ok': 1.0, 'err': None, 'n': 0, 'connectionId': 123}

Each response was leaked, and the memory added up fast if you called insert in a tight loop. The fix is simply to decref the response.

Published at DZone with permission of A. Jesse Jiryu Davis, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)