Skip to content

gh-160513: Call connection_lost() when start_tls() handshake is lost - #160514

Open
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-sslproto-a6ziafvt
Open

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-sslproto-a6ziafvt

Conversation

@gpshead

@gpshead gpshead commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

SSLProtocol.connection_lost() did not forward to the application protocol while the handshake was in progress. That is right for create_connection(ssl=...) and create_server(ssl=...), where the protocol has not had connection_made() yet, but not for start_tls(), where it has. The method now decides on the application protocol state alone, which already tells the two cases apart (STATE_INIT vs. STATE_CON_MADE). After a connection reset, a handshake timeout or a cancelled start_tls() the protocol now gets connection_lost(), and StreamWriter.wait_closed() completes instead of waiting forever.

A protocol passed to start_tls() now gets a connection_lost() call in these cases that it did not get before (with None when start_tls() was cancelled); that is the documented contract. The reset test accepts any ConnectionError because it was only run on selector event loops.

Fixes #160513

ANT-2026-A6ZIAFVT ANT-2026-4SKWM05E

… lost

SSLProtocol.connection_lost() did not notify the application protocol
while a handshake was in progress, even when start_tls() had handed
over a protocol that had already seen connection_made().  With streams
this left StreamWriter.wait_closed() waiting forever.
self.loop.start_tls(tr, proto, client_context),
0.5)

self.assertIsNone(await on_con_lost)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have timeout as well, otherwise it will hang forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

start_tls() does not call connection_lost() when the handshake is aborted

2 participants