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

3-replica set MongoDB cluster throw an Exception in thread pymongo_server_monitor_thread when handling concurrent queries

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Query Operations
    • None
    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Detailed steps to reproduce the problem?

      Background:
      Env: 3-replicaSet cluster
      MongoDB 5.0.13 & pymongo 3.13.0 & Python 3.10.11 & CentOS 8

      My application uses gevent with its standard monkey_patch. The same code logic worked fine with Python 2.7 and older pymongo versions, but started failing after upgrading. Upgrading pymongo from 3.13.0 to 4.3~4.11 didn’t resolve it.
      I had to create a custom time patch for _receive_cluster_time_no_lock as a workaround.

      From examining pymongo source code, I suspect the error occurs when processing operation.client._process_response(first, operation.session), where the first parameter’s clusterTime is interpreted as an int?

      Bug detail print:

      Exception in thread pymongo_server_monitor_thread:
      Traceback (most recent call last):
      File "/opt/smtx/python310/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
      self.run()
      File "/opt/smtx/python310/lib/python3.10/threading.py", line 953, in run
      self._target(*self._args, **self._kwargs)
      File "/usr/local/venv/turbot/lib/python3.10/site-packages/pymongo/periodic_executor.py", line 125, in _run
      if not self._target():
      File "/usr/local/venv/turbot/lib/python3.10/site-packages/pymongo/monitor.py", line 52, in target
      monitor._run()  # type:ignore[attr-defined]
      File "/usr/local/venv/turbot/lib/python3.10/site-packages/pymongo/monitor.py", line 186, in _run
      self._topology.on_change(
      File "/usr/local/venv/turbot/lib/python3.10/site-packages/pymongo/topology.py", line 371, in on_change
      self._process_change(server_description, reset_pool)
      File "/usr/local/venv/turbot/lib/python3.10/site-packages/pymongo/topology.py", line 329, in _process_change
      self._receive_cluster_time_no_lock(server_description.cluster_time)
      File "/usr/local/venv/turbot/lib/python3.10/site-packages/pymongo/topology.py", line 459, in _receive_cluster_time_no_lock
      or cluster_time["clusterTime"] > self._max_cluster_time["clusterTime"]
      TypeError: '>' not supported between instances of 'Timestamp' and 'int'

            Assignee:
            iris.ho@mongodb.com Iris Ho
            Reporter:
            xu.han@smartx.com Xu Han
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: