PYTHON-5821 - Fix ordering issue between event publish and logging for Pool monitoring tests#2796
Merged
NoahStapp merged 1 commit intomongodb:masterfrom May 7, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts PyMongo’s connection pool lifecycle instrumentation so that Pool debug log messages are emitted before the corresponding CMAP pool events, reducing nondeterministic ordering between logs and event publication.
Changes:
- Reordered
publish_pool_createdto occur after thePOOL_CREATEDdebug log. - Reordered
publish_pool_ready,publish_pool_closed, andpublish_pool_clearedto occur after their corresponding debug logs. - Applied the same ordering changes to both synchronous and asynchronous pool implementations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pymongo/synchronous/pool.py | Reorders pool lifecycle log emission ahead of CMAP pool events (created/ready/cleared/closed). |
| pymongo/asynchronous/pool.py | Mirrors the same log-before-event ordering changes for the async pool. |
| self.opts._event_listeners.publish_pool_created( | ||
| self.address, self.opts.non_default_options | ||
| ) | ||
| # Log before publishing event to prevent potential listener preemption in tests |
sleepyStick
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PYTHON-5821
Changes in this PR
Emit
Pooldebug log messages beforePoolevents.Before this change,
Poolevents publish before the corresponding logs emit. In the synchronous API, this can cause the following ordering issue in tests such astest.test_connection_logging.TestConnectionLoggingConnectionPoolOptions.test_waitQueueTimeoutMS_should_be_included_in_connection_pool_created_message_when_specified:wait_untilto poll for the event being published.Poolpublishes the event from the monitor thread.wait_untilpreempts thePool's thread and sees that the event has been published. This causes the test to run its assertions, which fail since the log has not been emitted.Test Plan
Existing connection logging + monitoring tests.
Checklist
Checklist for Author
[ ] Did you update the changelog (if necessary)?[ ] Is any followup work tracked in a JIRA ticket? If so, add link(s).Checklist for Reviewer