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

Client attempts to create background connections even with minPoolSize=0

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      In the repro script for HELP-23347 the MongoClient is not configured with minPoolSize and yet the background thread still attempts to create a connection for the pool. This is a bug.

      2021-04-08 11:20:45,234 INFO Connecting to:
       mongodb://XXX:XXX@redactedhost:27017,redactedhost2:27017,redactedhost3:27017/test?retryWrites=true&authSource=admin
      ...
      ... redactedhost:27017 becomes unreachable and minPoolSize is not configured
      ...
      2021-04-08 11:36:48,033 INFO [pool ('redactedhost', 27017)] pool cleared
      2021-04-08 11:36:48,529 INFO Topology description updated for topology id 606ee70d3e8b5aff0ebb6fcb
      2021-04-08 11:36:49,441 INFO Command insert with request id 1469543483 on server ('redactedhost', 27017) failed in 933415140 microseconds, with error: {'errmsg': '[Errno 113] No route to host', 'errtype': 'OSError'}
      2021-04-08 11:36:49,441 INFO [pool ('redactedhost', 27017)][conn #1] connection closed, reason: error
      2021-04-08 11:36:49,441 INFO [pool ('redactedhost', 27017)][conn #1] connection checked into pool
      ...
      2021-04-08 11:36:49,530 INFO [pool ('redactedhost', 27017)][conn #2] connection created
      2021-04-08 11:36:51,105 INFO [pool ('redactedhost', 27017)][conn #2] connection closed, reason: error
      Traceback (most recent call last):
        File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 1180, in connect
          sock = _configured_socket(self.address, self.opts)
        File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 988, in _configured_socket
          sock = _create_connection(address, options)
        File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 972, in _create_connection
          raise err
        File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 965, in _create_connection
          sock.connect(sa)
      OSError: [Errno 113] No route to host
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/usr/local/lib64/python3.7/site-packages/pymongo/mongo_client.py", line 1752, in _process_periodic_tasks
          self._topology.update_pool(self.__all_credentials)
        File "/usr/local/lib64/python3.7/site-packages/pymongo/topology.py", line 441, in update_pool
          server._pool.remove_stale_sockets(generation, all_credentials)
        File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 1152, in remove_stale_sockets
          sock_info = self.connect(all_credentials)
        File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 1187, in connect
          _raise_connection_failure(self.address, error)
        File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 286, in _raise_connection_failure
          raise AutoReconnect(msg)
      pymongo.errors.AutoReconnect: redactedhost:27017: [Errno 113] No route to host
      

      What's odd is that the background thread only starts attempting to create connections after the closed connection (which was stalled for 16 minutes) is checked back into the pool. So the order of events are:

      • Create pool with minPoolSize 0
      • Pool creates a connection for insert operations. This connection is checked in and out many times.
      • The primary becomes unreachable and connection remains checked out for 16 minutes.
      • SDAM heartbeats fail due to timeout errors and clear the pool many times.
      • After 16 minutes, the closed connection is checked back into the pool
      • Finally, the background thread immediately attempts to create a connection for the same pool.

      I suspect something about the pool's remove_stale_sockets is incorrect or clearing the pool potentially leaves the internal state inconsistent.

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

              Created:
              Updated:
              Resolved: