Repository navigation
Conversation
…t connection Closing an SSL transport that was already marked closed, e.g. from the protocol's connection_lost(), detached it from its SSLProtocol, so later calls such as write() or set_protocol() raised AttributeError. This hit the loop.sendfile() fallback when the peer went away mid-transfer. Keep the protocol and instead release the SSL object and context, which is what the detaching was for (pythonGH-98539). If the shutdown is still in progress, release them when the connection is lost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gpshead
approved these changes
Oct 31, 2026
gpshead
left a comment
Member
There was a problem hiding this comment.
I think this PR is correct, but it looks like you've already noticed the overlap with #160069 which also adds a sendfile and leak test. You might want to pick a few bits from that if those tests are relevant.
Logic difference: do we need to care about the release happening before or after theconnection_lost() callback? this one does it before, I think the other PR does it after.
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.
Closing an SSL transport that is already marked closed, for example from the protocol's
connection_lost(), used to detach it from itsSSLProtocolby setting_ssl_protocol = None(added in gh-98539). After that,write(),set_protocol(),get_write_buffer_size()andget_extra_info()raisedAttributeError. Theloop.sendfile()fallback hits this inrestore()when the peer disconnects mid-transfer.The transport now keeps its protocol. Instead,
SSLProtocol._release_ssl()drops the SSL object, the context and theirssl_object/sslcontextextra info, which is what the detaching was meant to achieve. If the TLS shutdown is still in progress (for example when the peer started it, so the app's firstclose()already lands in that branch), the release waits untilconnection_lost().A single
close()behaves as before, so the app can still readget_extra_info('ssl_object')in itsconnection_lost().Tests: two new unit tests in
test_sslproto; both fail onmain. The existingtest_ssl.test_create_connection_memory_leakstill passes, andtest_asyncioandtest_sslpass on Linux.🤖 Generated with Claude Code