PYTHON-5919 Recognize PyOpenSSL EOF errors as SystemOverloadedError#2921
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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_ERRORSdefinition inpymongo.ssl_support. - Updates connection-error handling in both async and generated sync pools to use
SSL_EOF_ERRORSwhen deciding whether to label overload. - Adds regression/unit tests covering stdlib
sslEOF errors and PyOpenSSLSysCallError/ZeroReturnErrorcauses.
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. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
NoahStapp
approved these changes
Jul 8, 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-5919
Changes in this PR
Fixes a bug where
TestPoolBackpressure.test_connection_pool_is_not_clearedfails 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
Checklist for Reviewer