Repository navigation
Fix SSLStream waiter hang after a failed or cancelled handshake - #3596
Open
DeviousCardi wants to merge 1 commit into
Open
DeviousCardi wants to merge 1 commit into
DeviousCardi wants to merge 1 commit into
Conversation
_Once.ensure() set its done event only on a successful handshake, so concurrent send/receive tasks waited forever when the handshake raised or was cancelled. Signal the event in a finally block, record failure, and make waiters raise BrokenResourceError. Successful-handshake behavior is unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3596 +/- ##
====================================================
+ Coverage 98.16743% 100.00000% +1.83257%
====================================================
Files 128 128
Lines 19972 19671 -301
Branches 1399 1337 -62
====================================================
+ Hits 19606 19671 +65
+ Misses 359 0 -359
+ Partials 7 0 -7
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Fixes #3581.
_Once.ensure()set its done event only after a successful handshake. If the handshake raised (EOF, reset, certificate error) or the task running it was cancelled, concurrentsend_all/receive_some/do_handshaketasks stayed parked inawait self._done.wait()forever.The event is now set in a
finallyblock, with a_failedflag recorded on failure. Waiters raiseBrokenResourceError, matching later use of the stream, while the task that ran the handshake keeps its original exception/cancellation.donenow means “completed successfully”, so guarded forwarders still raiseNeedHandshakeErrorafter a failed handshake.Tests use the issue's
memory_stream_pairreproducer for handshake failure, cancellation and concurrent success, all withfail_afterso a regression fails instead of hanging.test_ssl.pypasses (70 passed, 2 skipped); the new tests fail on the unpatched tree. Ruff, black, mypy andgit diff --checkare clean.