Fix async-only constructs left in the synchronous monitor and topology code

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Monitoring
    • 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

      Context

      PYTHON-5053 added a Monitor.join() override so that closing a client waits for both
      the heartbeat executor and the RTT monitor, plus a Topology.cleanup_monitors() helper
      to drain pending monitors. Both work as intended on the async side. The generated
      synchronous versions retain async-only constructs. Monitor.join() raises
      TypeError unconditionally, and cleanup_monitors() silently does nothing while
      emitting a DeprecationWarning about there being no event loop.

      Neither is reachable today. cleanup_monitors() is the only caller of
      Monitor.join(), and both of its own call sites are gated to async-only. The monitor
      list it drains is never populated in the sync driver. Confirmed against a local replica
      set: across normal operations and close(), the list stays empty and
      cleanup_monitors() is never invoked. Synchronous MongoClient.close() returns
      without joining and leaves monitor threads to wind down on their own as daemon threads,
      matching the behavior from before PYTHON-5053. There is no user-facing regression.

      Note also that the joins in the sync Monitor.join() override do complete before the
      TypeError is raised, so the waiting it was meant to express is already happening.

      Definition of done

      • Synchronous Monitor.join() returns without raising and waits for both the
        heartbeat executor and the RTT monitor.
      • Synchronous cleanup_monitors() drains and joins pending monitors without warnings.
      • Regression tests exercise both synchronous methods directly.
      • Async behavior is unchanged.

      Pitfalls

      • Type checking will not catch a partial fix. The type: ignore comments the async
        source requires are copied into the generated sync files, where they suppress real
        errors describing these bugs.
      • A green test suite proves nothing, since neither method currently has callers. The new
        tests are the only signal.
      • Other uses of the same async construct in the driver are explicitly branched for sync.
        Follow that pattern so generated output stays valid.
      • join() waits without a bound, so a test must signal the executors to stop first or
        it will hang.
      • A test for cleanup_monitors() has to populate the monitor list itself, since
        nothing in the sync driver ever does.
      • Out of scope: making synchronous MongoClient.close() join monitors, which would
        change shutdown latency for all sync users.

            Assignee:
            Unassigned
            Reporter:
            Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: