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: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Query Operations
    • None
    • Python Drivers
    • 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:
            3 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None