Disconnection is not detected with tailable cursor

XMLWordPrintableJSON

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

      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 Lawley
              Reporter:
              Flavien
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: