Skip to content

PYTHON-6143 Fix TestKmsTLSOptions on Windows - #3097

Merged
aclark4life merged 1 commit into
mongodb:mainfrom
aclark4life:PYTHON-6143-fix-kms-tls-windows
Oct 6, 2026
Merged

aclark4life merged 1 commit into
mongodb:mainfrom
aclark4life:PYTHON-6143-fix-kms-tls-windows

Conversation

@aclark4life

@aclark4life aclark4life commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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_into on that socket 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 escapes the BLOCKING_IO_ERRORS handling and surfaces as a different error than the graceful close the KMS path expects. Map the reset to OSError("connection closed") in the Windows receive loop.

Test Plan

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)? No changelog impact (test-only failure on CI images).
  • Is the intention of the code captured in relevant tests? TestKmsTLSOptions.
  • If there are new TODOs, has a related JIRA ticket been created? None.

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?)
  • Have you checked for spelling & grammar errors?
  • Is all relevant documentation (README or docstring) updated?

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>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 21:28
@aclark4life
aclark4life requested a review from a team as a code owner October 5, 2026 21:28
@aclark4life
aclark4life requested a review from blink1073 October 5, 2026 21:28

Copilot AI 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.

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

codecov Bot commented Oct 5, 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/network_layer.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@blink1073 blink1073 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@aclark4life
aclark4life merged commit 9078654 into mongodb:main Oct 6, 2026
90 of 94 checks passed
@aclark4life
aclark4life deleted the PYTHON-6143-fix-kms-tls-windows branch October 6, 2026 20:45
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