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

Topology.close can open sockets and background threads

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.9
    • None
    • None
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: