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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.1
    • Component/s: None
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: