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

pymongo resends client metadata after Monitor heartbeats fail

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.6.1
    • Affects Version/s: 3.6
    • Component/s: Internal
    • None

      In 3.6, isMaster can fail because of an invalid "$clusterTime". For example:

      {'operationTime': Timestamp(1512689435, 1), 'ok': 0.0, 'errmsg': 'Cache Reader No keys found for HMAC that is valid for time: { ts: Timestamp(1512689525, 0) } with id: 0', 'code': 211, 'codeName': 'KeyNotFound', '$clusterTime': {'clusterTime': Timestamp(1512689435, 1), 'signature': {'hash': b'\xeey\x10\x19\xa32/\x1fD\xaa8\x9c\x97*\xa2\xf3\xe7\x8f\xfe[', 'keyId': 6496946060282298369}}}
      

      After isMaster fails, PyMongo sets the server type to UNKNOWN. On the next check, the Monitor will erroneously resend client metadata: https://github.com/mongodb/mongo-python-driver/blob/3.6.0/pymongo/monitor.py#L117-L119.

      Sending client metadata a second time on the same connection is an error:

      {'ok': 0.0, 'errmsg': 'The client metadata document may only be sent in the first isMaster', 'code': 186, 'codeName': 'ClientMetadataCannotBeMutated', 'operationTime': Timestamp(1512689445, 1), '$clusterTime': {'clusterTime': Timestamp(1512689445, 1), 'signature': {'hash': b'\xaf\xeemS\x80\xd4\\t\x84\xaf\xe03\x7f\x93\xf3S\xfc\x85E\xfc', 'keyId': 6496946060282298369}}}
      

      The server type is reset to UNKNOWN and client metadata is resent. Repeat forever. Attempting to use the client in this state results in a "ServerSelectionTimeoutError: No servers found yet" error.

      This means that a single invalid "$clusterTime" returned from the server, such as SERVER-31916, can prevent a MongoClient from connecting forever.

      Related to: https://github.com/10gen/mongo-orchestration/issues/235

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

              Created:
              Updated:
              Resolved: