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

In pymongo/connection.py, function _closed can be simplified

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.1
    • Affects Version/s: 2.0
    • Component/s: None
    • None
    • Fully Compatible

      Function _closed(sock) uses sock.recv() without parameters, which always raises a TypeError and thus if there's data in the socket it will return True anyway. This patch removes the call to sock.recv() because it is not needed, what's worse is that would it ever succeed some data would be removed from the socket and its state would become inconsistent.

      So the only check needed is to check if len(rd) is non-zero, because if it is the socket is either closed or has unexpected data, in either case it cannot be used safely.

        1. closed-fix.patch
          0.4 kB
          Alexey Borzenkov

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            snaury Alexey Borzenkov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: