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

Topology.close can open sockets and background threads

    XMLWordPrintable

    Details

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

      Description

      Topology.close() calls self._update_servers() which will open new Monitor threads and connection pools for servers that are in the topology description but not in the self.servers dict: https://github.com/mongodb/mongo-python-driver/blob/3.8.0/pymongo/topology.py#L399

      A simple repro is creating a client with connect=False and then calling close:

      >>> client = MongoClient(connect=False)
      >>> client._topology._servers
      {}
      >>> client.close()
      >>> client._topology._servers
      {('localhost', 27017): <pymongo.server.Server object at 0x10bd10e80>}
      >>> client._topology._servers[('localhost', 27017)]._monitor._executor._thread
      <weakproxy at 0x10bd35098 to Thread at 0x10bd10e48>
      

      I think the simple fix is to remove the call to self._update_servers().

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shane.harvey Shane Harvey
              Reporter:
              shane.harvey Shane Harvey
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: