Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-33

Motor takes 100% CPU when deleting cursor object

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 0.2.1
    • Affects Version/s: 0.2
    • Component/s: None
    • Labels:
      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.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: