Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-415

Disconnection is not detected with tailable cursor

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4
    • Affects Version/s: 2.2
    • Component/s: None
    • Labels:

      I am using tailable cursors to read a capped collection as it get written:

          while True:
              try:
                  with collection.find(tailable=True, await_data=True, timeout=True, sort=[("$natural", ASCENDING)]) as cursor:
                      while cursor.alive:
                          for doc in cursor:
                              callback(doc)
                                  
                  gevent.sleep(1)
              except:
                  trace_exception()
      

      It works fine most of the time, however I noticed a problem happening randomly. Sometimes, if I shut down the MongoDB server, the cursor doesn't detect the disconnection, and stays in an endless loop without raising any error.

      I think the problem may be in cursor.py. In refresh, self._id appears to be 0, so the "elif self._id" statement is skipped, and the cursor doesn't try to get more data from the server, so no error is ever raised.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            flavien Flavien
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: