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

Client Connection Regression with PSA + minPoolSize/maxPoolSize

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.11.1, 3.11.2, 3.11.3
    • Fix Version/s: 3.12, 3.11.4, 4.0
    • Component/s: None
    • Labels:
      None
    • Case:

      Description

      This issue occurs when:

      • PyMongo version is >= 3.11
      • Cluster is a replica set with an arbiter
      • Cluster has authentication enabled
      • URI Options include minPoolSize and maxPoolSize

      $ mlaunch init --replicaset --nodes 2 --arbiter --auth --port 27027 --binarypath $(m bin 4.2.12)
      $ python test.py 
      Connection String:  mongodb://user:password@localhost:27027,localhost:27028,localhost:27029/admin?replicaSet=replset&w=majority&readPreference=secondaryPreferred&minPoolSize=1&maxPoolSize=4
      PyMongo Version:  3.10.1
      {'hosts': ['localhost:27027', 'localhost:27028'], 'arbiters': ['localhost:27029'], 'setName': 'replset', 'setVersion': 1, 'ismaster': True, 'secondary': False, 'primary': 'localhost:27027', 'me': 'localhost:27027', 'electionId': ObjectId('7fffffff0000000000000001'), 'lastWrite': {'opTime': {'ts': Timestamp(1617654986, 20), 't': 1}, 'lastWriteDate': datetime.datetime(2021, 4, 5, 20, 36, 26), 'majorityOpTime': {'ts': Timestamp(1617654986, 20), 't': 1}, 'majorityWriteDate': datetime.datetime(2021, 4, 5, 20, 36, 26)}, 'maxBsonObjectSize': 16777216, 'maxMessageSizeBytes': 48000000, 'maxWriteBatchSize': 100000, 'localTime': datetime.datetime(2021, 4, 5, 20, 36, 36, 211000), 'logicalSessionTimeoutMinutes': 30, 'connectionId': 105, 'minWireVersion': 0, 'maxWireVersion': 8, 'readOnly': False, 'ok': 1.0, '$clusterTime': {'clusterTime': Timestamp(1617654986, 20), 'signature': {'hash': b"#n\xe7\xad\x11`j\\\xb3\xc8\xda5\xca\x83\xf79\xed'\xd8d", 'keyId': 6947772757115404291}}, 'operationTime': Timestamp(1617654986, 20)}
      

      No issues using 3.10.x, however when the requirements are updated:

      $ pip install -r requirements.txt 
      Collecting pymongo==3.11.3
        Using cached pymongo-3.11.3-cp38-cp38-manylinux2014_x86_64.whl (531 kB)
      Installing collected packages: pymongo
        Attempting uninstall: pymongo
          Found existing installation: pymongo 3.10.1
          Uninstalling pymongo-3.10.1:
            Successfully uninstalled pymongo-3.10.1
      Successfully installed pymongo-3.11.3
      $ python test.py 
      Connection String:  mongodb://user:password@localhost:27027,localhost:27028,localhost:27029/admin?replicaSet=replset&w=majority&readPreference=secondaryPreferred&minPoolSize=1&maxPoolSize=4
      PyMongo Version:  3.11.3
      Traceback (most recent call last):
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1752, in _process_periodic_tasks
          self._topology.update_pool(self.__all_credentials)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/topology.py", line 441, in update_pool
          server._pool.remove_stale_sockets(generation, all_credentials)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/pool.py", line 1152, in remove_stale_sockets
          sock_info = self.connect(all_credentials)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/pool.py", line 1197, in connect
          sock_info.check_auth(all_credentials)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/pool.py", line 793, in check_auth
          self.authenticate(credentials)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/pool.py", line 810, in authenticate
          auth.authenticate(credentials, self)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/auth.py", line 673, in authenticate
          auth_func(credentials, sock_info)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/auth.py", line 591, in _authenticate_default
          return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/auth.py", line 295, in _authenticate_scram
          res = sock_info.command(source, cmd)
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/pool.py", line 683, in command
          return command(self, dbname, spec, slave_ok,
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/network.py", line 159, in command
          helpers._check_command_response(
        File "/home/alex/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymongo/helpers.py", line 164, in _check_command_response
          raise OperationFailure(errmsg, code, response, max_wire_version)
      pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
      {'hosts': ['localhost:27027', 'localhost:27028'], 'arbiters': ['localhost:27029'], 'setName': 'replset', 'setVersion': 1, 'ismaster': True, 'secondary': False, 'primary': 'localhost:27027', 'me': 'localhost:27027', 'electionId': ObjectId('7fffffff0000000000000001'), 'lastWrite': {'opTime': {'ts': Timestamp(1617655013, 1), 't': 1}, 'lastWriteDate': datetime.datetime(2021, 4, 5, 20, 36, 53), 'majorityOpTime': {'ts': Timestamp(1617655013, 1), 't': 1}, 'majorityWriteDate': datetime.datetime(2021, 4, 5, 20, 36, 53)}, 'maxBsonObjectSize': 16777216, 'maxMessageSizeBytes': 48000000, 'maxWriteBatchSize': 100000, 'localTime': datetime.datetime(2021, 4, 5, 20, 36, 57, 375000), 'logicalSessionTimeoutMinutes': 30, 'connectionId': 107, 'minWireVersion': 0, 'maxWireVersion': 8, 'readOnly': False, 'ok': 1.0, '$clusterTime': {'clusterTime': Timestamp(1617655013, 1), 'signature': {'hash': b'\x82?\x84\x05\xc5\x86+\xac\x8c\x9e\xc4\x90\xcd)M\x86\x7fJ<\xc8', 'keyId': 6947772757115404291}}, 'operationTime': Timestamp(1617655013, 1)}
      

      Issue occurs in PSA configuration, but not in PSS.

      It appears the connection is established prior to the OperationFailure being raised.

      test.py code is below:

      import pymongo
      from pymongo import MongoClient
      from pymongo.errors import InvalidOperation
       
      try:
      	_url = 'mongodb://user:password@localhost:27027,localhost:27028,localhost:27029/admin?replicaSet=replset&w=majority&readPreference=secondaryPreferred&minPoolSize=1&maxPoolSize=4'
      	c = MongoClient(_url)
      	print("Connection String: ", _url)
      	print("PyMongo Version: ", pymongo.version)
      	print(c.test.command("ismaster"))
      except InvalidOperation as err:
      	print("Unexpected error:", err)
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shane.harvey Shane Harvey
              Reporter:
              alex.bevilacqua Alex Bevilacqua
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: