Repository navigation
Conversation
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.
This PR. fixes #148594 and fixes #81891 (duplicate reports of the same bug), following the discussion in #148597.
Stale entries in the thread-local OpenSSL error queue can cause
SSL_get_error()to misclassify retryable conditions, leading to spurious exceptions.Clear the queue immediately before each
SSL_read_ex(),SSL_write_ex(),SSL_do_handshake(),SSL_shutdown()andSSL_sendfile()invocation, including retries. Error classification remains immediately after each operation.Clearing errors only where CPython raises them would not cover entries left by other OpenSSL users on the same thread. Clearing at the I/O. call sites ensures that the precondition is met regardless of where the stale errors originated.
Add regression tests for
read(),write()andunwrap(), based on the reproducer provided by @devdanzin in #148594. They reuse the existing test infrastructure and certificate fixtures without requiringctypes, gevent, external network access or certificate generation. All three fail before the fix and pass afterwards.The handshake and sendfile changes enforce the same documented precondition. A stale-queue failure has not been reproduced in the handshake path, and Kernel TLS sendfile was not tested on macOS.
SSL_pending()is unchanged because it reports buffered byte counts rather than the result of a TLS. I/O. operation.Validation on macOS arm64 with a CPython 3.16 debug build and OpenSSL 3.5.9:
./python.exe -m test test_ssl./python.exe -m test -R 3:3 test_ssl./python.exe -m test -j0make patchcheckAll checks passed. No leaks were reported after warm-up. The default suite completed with platform and resource skips.