Repository navigation
[3.14] gh-159875: Keep the SSL protocol of a closed transport after connection loss (GH-160069) - #161208
Merged
Conversation
…nnection loss (pythonGH-160069) * pythongh-159875: Add tests for an SSL transport closed after connection loss An application that closes its transport from connection_lost(), as aiohttp does, must be left with a transport whose write(), get_write_buffer_size() and set_protocol() behave as after closing a live connection, and loop.sendfile()'s fallback must then raise ConnectionError rather than AttributeError from set_protocol(). The sendfile test reads the file synchronously, so that the fallback is waiting in drain() when the connection is lost; a read in the executor that completes in the same loop iteration as the reset lets the fallback finish first and hides the bug. test_create_connection_memory_leak now keeps the transport past its check, as its comment says it covers, so that it would see an SSLContext kept alive by a transport the application still holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pythongh-159875: Keep the SSL protocol of a closed transport after connection loss _SSLProtocolTransport.close() dropped its _ssl_protocol when called a second time, and the transport is already marked closed once the connection is lost, so an application closing it from connection_lost() left a transport whose write(), set_protocol(), get_write_buffer_size(), ... raise AttributeError. That branch was also what released the SSLContext of a transport the application keeps. Keep the protocol, and release the TLS state from SSLProtocol.connection_lost() instead: one loop iteration later when the application's connection_lost() was scheduled, so that it can still read get_extra_info('ssl_object') and ('sslcontext'). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- (cherry picked from commit 0626b14) Co-authored-by: Mauricio Paez <jose.m.paez@icloud.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
miss-islington
requested review from
1st1,
asvetlov,
gpshead and
picnixz
as code owners
November 2, 2026 20:52
miss-islington
requested review from
kumaraditya303 and
willingc
as code owners
November 2, 2026 20:52
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.
transport.close()leaves a transport whosewrite(),set_protocol(), … raiseAttributeError#159875: Add tests for an SSL transport closed after connection lossAn application that closes its transport from connection_lost(), as aiohttp
does, must be left with a transport whose write(), get_write_buffer_size()
and set_protocol() behave as after closing a live connection, and
loop.sendfile()'s fallback must then raise ConnectionError rather than
AttributeError from set_protocol().
The sendfile test reads the file synchronously, so that the fallback is
waiting in drain() when the connection is lost; a read in the executor that
completes in the same loop iteration as the reset lets the fallback finish
first and hides the bug.
test_create_connection_memory_leak now keeps the transport past its check,
as its comment says it covers, so that it would see an SSLContext kept alive
by a transport the application still holds.
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
transport.close()leaves a transport whosewrite(),set_protocol(), … raiseAttributeError#159875: Keep the SSL protocol of a closed transport after connection loss_SSLProtocolTransport.close() dropped its _ssl_protocol when called a second
time, and the transport is already marked closed once the connection is lost,
so an application closing it from connection_lost() left a transport whose
write(), set_protocol(), get_write_buffer_size(), ... raise AttributeError.
That branch was also what released the SSLContext of a transport the
application keeps. Keep the protocol, and release the TLS state from
SSLProtocol.connection_lost() instead: one loop iteration later when the
application's connection_lost() was scheduled, so that it can still read
get_extra_info('ssl_object') and ('sslcontext').
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
(cherry picked from commit 0626b14)
Co-authored-by: Mauricio Paez jose.m.paez@icloud.com
Co-authored-by: Claude Opus 5.5 noreply@anthropic.com