Skip to content

PYTHON-5919 Recognize PyOpenSSL EOF errors as SystemOverloadedError#2921

Merged
blink1073 merged 1 commit into
mongodb:masterfrom
blink1073:PYTHON-5919
Jul 8, 2026
Merged

PYTHON-5919 Recognize PyOpenSSL EOF errors as SystemOverloadedError#2921
blink1073 merged 1 commit into
mongodb:masterfrom
blink1073:PYTHON-5919

Conversation

@blink1073

Copy link
Copy Markdown
Member

PYTHON-5919

Changes in this PR

Fixes a bug where TestPoolBackpressure.test_connection_pool_is_not_cleared fails on PyOpenSSL variants: connection-establishment failures caused by server-side backpressure were not being recognized as overload conditions, causing the connection pool to be cleared instead of just retried.

Test Plan

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?

Pool._handle_connection_error only exempted stdlib ssl.SSLEOFError/
SSLZeroReturnError from the SSL-error exclusion check. Under PyOpenSSL,
a rate limiter closing the socket during the TLS handshake raises
OpenSSL.SSL.SysCallError/ZeroReturnError instead, so the
SystemOverloadedError label was never added and the pool was cleared.

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.

Pull request overview

This PR addresses PYTHON-5919 by ensuring that TLS-handshake EOF failures raised by PyOpenSSL are treated as overload/backpressure signals (labeled SystemOverloadedError) rather than causing the connection pool to be cleared, aligning PyOpenSSL behavior with stdlib ssl.

Changes:

  • Centralizes “TLS handshake EOF” exception detection via a new SSL_EOF_ERRORS definition in pymongo.ssl_support.
  • Updates connection-error handling in both async and generated sync pools to use SSL_EOF_ERRORS when deciding whether to label overload.
  • Adds regression/unit tests covering stdlib ssl EOF errors and PyOpenSSL SysCallError / ZeroReturnError causes.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/test_pooling.py Adds mirrored regression tests for overload labeling when TLS handshake ends with EOF (stdlib + PyOpenSSL).
test/asynchronous/test_pooling.py Adds source regression tests for overload labeling when TLS handshake ends with EOF (stdlib + PyOpenSSL).
pymongo/synchronous/pool.py Uses SSL_EOF_ERRORS in overload labeling logic (generated from async).
pymongo/asynchronous/pool.py Uses SSL_EOF_ERRORS in overload labeling logic.
pymongo/ssl_support.py Introduces SSL_EOF_ERRORS to unify stdlib + PyOpenSSL EOF error recognition.
pymongo/pyopenssl_context.py Exposes PyOpenSSL EOF-related exception classes via EOF_ERRORS.

Comment thread test/asynchronous/test_pooling.py
Comment thread pymongo/ssl_support.py
@blink1073
blink1073 marked this pull request as ready for review July 8, 2026 13:43
@blink1073
blink1073 requested a review from a team as a code owner July 8, 2026 13:43
@blink1073
blink1073 requested a review from NoahStapp July 8, 2026 13:43
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pymongo/ssl_support.py 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@blink1073
blink1073 merged commit 4b45e4b into mongodb:master Jul 8, 2026
99 of 102 checks passed
@blink1073
blink1073 deleted the PYTHON-5919 branch July 8, 2026 17: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.

4 participants