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

Topology.close can open sockets and background threads

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.9
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      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().

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

              Created:
              Updated:
              Resolved: