-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 0.2
-
Component/s: None
-
None
MotorCursor and MotorCommandCursor objects implement a __del__ method that checks if the cursor is still alive on the server and, if so, calls self.close() to send an OP_KILLCURSORS message to the server.
Starting with Motor 0.2, the coroutine implementation of self.close() changed such that it creates a new reference to the cursor object, rescuing it from garbage collection. If the cursor also has any documents in its buffer then its "alive" property is true. This created an infinite loop: each time the cursor began to delete itself, __del__ revived it.
An application in this situation is still responsive, since each call to self.close() yields control to the IOLoop. However, it pegs a CPU core, and sends useless OP_KILLCURSORS messages to the server as fast as it can.
The solution is to only call close() once. If self.closed is True, short-circuit.