Skip to content

[PYTHON-5904] RTT Thread Flips Between isMaster and hello#2904

Open
ronan-merrick wants to merge 4 commits into
mongodb:masterfrom
ronan-merrick:master
Open

[PYTHON-5904] RTT Thread Flips Between isMaster and hello#2904
ronan-merrick wants to merge 4 commits into
mongodb:masterfrom
ronan-merrick:master

Conversation

@ronan-merrick

Copy link
Copy Markdown

[JIRA TICKET]

Changes in this PR

I changed the connection to not set hello_ok back to False when the connection switches to hello from ismaster

Test Plan

I reperformed the tests described in the ticket to make sure the issue was no longer occurring and also wrote regression tests.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@ronan-merrick ronan-merrick requested a review from a team as a code owner June 30, 2026 12:53
@codecov-commenter

codecov-commenter commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pymongo/asynchronous/pool.py 0.00% 1 Missing ⚠️
pymongo/synchronous/pool.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@NoahStapp NoahStapp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read our CONTRIBUTING.md and ensure all changes conform to its guidelines, especially the Project Structure and Asyncio Considerations section.

Comment thread test/asynchronous/test_hello_latched.py Outdated
await conn._hello(None, None)
# Verify connection continues to use hello
self.assertEqual(self._sent[2].get("hello"), 1)
self.assertIsNone(self._sent[1].get("ismaster", None))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertIsNone(self._sent[1].get("ismaster", None))
self.assertIsNone(self._sent[2].get("ismaster", None))

Comment thread test/test_hello_latched.py Outdated
from pymongo.synchronous.pool import Connection


class TestHelloLatched(unittest.TestCase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file must be generated using the synchro pre-commit hook from the asynchronous version.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. I misunderstood that these run on commit.

@@ -0,0 +1,67 @@
import unittest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs the standard license header, see another test file for an example.

@ronan-merrick ronan-merrick requested a review from NoahStapp June 30, 2026 19:05

@NoahStapp NoahStapp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both changes need to be mirrored to the synchronous API. Please run just lint-manual locally to re-generate the synchronous code.

Comment thread pymongo/asynchronous/pool.py Outdated
)
self.logical_session_timeout_minutes: Optional[int] = hello.logical_session_timeout_minutes
self.hello_ok = hello.hello_ok
# PYTHON-5904

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this comment a little more informative rather than just the ticket name?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem.

@ronan-merrick ronan-merrick requested a review from NoahStapp July 1, 2026 10:33
@NoahStapp NoahStapp removed the request for review from aclark4life July 1, 2026 13:33

@NoahStapp NoahStapp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we need to update our CONTRIBUTING.md to be clearer and more helpful for adding new test suites.

You need to add test_hello_latched.py to the converted_tests list in tools/synchro.py, then run just lint-manual to generate the synchronous test. You'll also need to add "AsyncMock: Mock" to the replacements dictionary in tools/synchro.py to correctly convert the import from async to sync in the generated file.

@@ -0,0 +1,79 @@
# Copyright 2022-present MongoDB, Inc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright 2022-present MongoDB, Inc.
# Copyright 2026-present MongoDB, Inc.


from pymongo.asynchronous.pool import AsyncConnection


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line _IS_SYNC = False needs to be here after the imports.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I will make these changes.
Thanks Noah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants