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

PyMongo does not truncate client metadata document to 512 bytes

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.9
    • Affects Version/s: None
    • Component/s: None
    • Not Needed

      PyMongo does not truncate client metadata document to 512 bytes:

      >>> from pymongo.driver_info import DriverInfo
      >>> client = MongoClient(driver=DriverInfo(name='s'*512))
      >>> client.admin.command('isMaster')
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "pymongo/database.py", line 730, in command
          read_preference, session) as (sock_info, slave_ok):
        File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
          return self.gen.next()
        File "pymongo/mongo_client.py", line 1301, in _socket_for_reads
          with self._get_socket(server, session) as sock_info:
        File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
          return self.gen.next()
        File "pymongo/mongo_client.py", line 1223, in _get_socket
          self.__all_credentials, checkout=exhaust) as sock_info:
        File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
          return self.gen.next()
        File "pymongo/pool.py", line 1126, in get_socket
          sock_info = self._get_socket_no_auth()
        File "pymongo/pool.py", line 1178, in _get_socket_no_auth
          sock_info = self.connect()
        File "pymongo/pool.py", line 1093, in connect
          sock_info.ismaster(self.opts.metadata, None)
        File "pymongo/pool.py", line 516, in ismaster
          ismaster = IsMaster(self.command('admin', cmd, publish_events=False))
        File "pymongo/pool.py", line 614, in command
          user_fields=user_fields)
        File "pymongo/network.py", line 167, in command
          parse_write_concern_error=parse_write_concern_error)
        File "pymongo/helpers.py", line 159, in _check_command_response
          raise OperationFailure(msg % errmsg, code, response)
      pymongo.errors.OperationFailure: The client metadata document must be less then or equal to 512bytes
      

      The handshake spec says:

      The entire metadata BSON document MUST NOT exceed 512 bytes. This includes all BSON overhead. The client.application.name cannot exceed 128 bytes. MongoDB will return an error if these limits are not adhered to, which will result in handshake failure. Drivers MUST validate these values and truncate driver provided values if necessary.

      https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#limitations

            Assignee:
            shruti.sridhar@mongodb.com Shruti Sridhar (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: