Repository navigation
PYTHON-6143 Fix TestKmsTLSOptions on Windows - #3097
Merged
aclark4life merged 1 commit intoOct 6, 2026
Merged
Conversation
On Windows the async SSL receive path busy-polls a non-blocking socket,
because the default Windows asyncio event loop does not support
loop.add_reader. On Python 3.14.7+ a non-blocking recv_into raises raw
ConnectionResetError (WinError 10054) when the peer closes without TLS
close_notify, as the mock KMS servers do, instead of returning 0 or
raising SSLError. The raw error escaped the BLOCKING_IO_ERRORS handling
and surfaced as a different error than the graceful close the KMS path
expects.
Map the reset to OSError('connection closed') in that loop.
Co-Authored-By: Claude Code <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused exception mapping is consistent with existing closed-connection handling and is covered by the cited Windows integration suite.
Review effort: Balanced
Findings: None
What changed in this PR
Normalizes Windows async TLS peer-reset handling for KMS connections.
Changes:
- Converts connection reset/abort exceptions into the expected closed-connection error.
- Documents the Python 3.14.7+ behavior.
| File | Description |
|---|---|
pymongo/network_layer.py |
Handles abrupt TLS peer closure in the Windows async receive loop. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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-6143
EVG: https://spruce.corp.mongodb.com/version/6ac40cdc06de780007b5e675/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC
Changes in this PR
On Windows the async SSL receive path busy-polls a non-blocking socket (the default Windows asyncio event loop does not support
loop.add_reader). On Python 3.14.7+recv_intoon that socket raises rawConnectionResetError(WinError 10054) when the peer closes without TLSclose_notify, as the mock KMS servers do, instead of returning 0 or raisingSSLError. The raw error escapes theBLOCKING_IO_ERRORShandling and surfaces as a different error than the graceful close the KMS path expects. Map the reset toOSError("connection closed")in the Windows receive loop.Test Plan
encryption-crypt_shared-win64tasks, Windows + Python 3.14.7): https://spruce.corp.mongodb.com/version/6ac40cdc06de780007b5e675TestKmsTLSOptionsfails deterministically (5-6 tests/run) on Windows + 3.14.7 without this change.Checklist
Checklist for Author
TestKmsTLSOptions.Checklist for Reviewer