Skip to content

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

Merged
gpshead merged 2 commits into
python:mainfrom
gpshead:scanfix-sslproto-a6ziafvt
Oct 25, 2026
Merged

gpshead merged 2 commits 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.
Comment thread Lib/test/test_asyncio/test_sslproto.py Outdated
@gpshead gpshead moved this from Todo to In Progress in Sprint Oct 25, 2026
Wait for on_con_lost with LOOPBACK_TIMEOUT, shorter than the
SHORT_TIMEOUT wrapping the whole client, so a missing connection_lost()
fails at that line.  Use SHORT_TIMEOUT instead of a hard-coded 10 in the
streams test.
@gpshead gpshead moved this from In Progress to Done in Sprint Oct 25, 2026
@gpshead
gpshead merged commit d9cfd30 into python:main Oct 25, 2026
57 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 25, 2026

Copy link
Copy Markdown

GH-160686 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 25, 2026
@bedevere-app

bedevere-app Bot commented Oct 25, 2026

Copy link
Copy Markdown

GH-160687 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 25, 2026
gpshead added a commit that referenced this pull request Oct 25, 2026
…s lost (GH-160514) (#160686)

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

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.

ANT-2026-A6ZIAFVT
ANT-2026-4SKWM05E
(cherry picked from commit d9cfd30)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
gpshead added a commit that referenced this pull request Oct 25, 2026
…s lost (GH-160514) (#160687)

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

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.

ANT-2026-A6ZIAFVT
ANT-2026-4SKWM05E
(cherry picked from commit d9cfd30)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

2 participants