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

Disconnection is not detected with tailable cursor

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.4
    • Component/s: None
    • Labels:

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            ross.lawley Ross Lawley
            Reporter:
            flavien Flavien
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: