Skip to content

Commit e5fad04

Browse files
asvetlovclaude
andauthored
gh-158646: Fix race in test_shutdown_corrupted_ssl_sends_close_notify (#160848)
The server called unwrap() right after corrupting the client's TLS stream, which sent its own close_notify to a client that was about to close its socket. That turned the client's close into a TCP reset, and on Windows a reset discards the client's close_notify that is still unread, so the server failed with WinError 10054 (or 10053). Wait for the client's close_notify with recv() before calling unwrap(). A ragged EOF without close_notify still makes unwrap() raise SSLError, so the test keeps catching the gh-98078 regression. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 16f209b commit e5fad04

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎Lib/test/test_asyncio/test_sslproto.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,15 @@ def server(sock):
10991099
orig_sock.send(b'please corrupt the SSL connection')
11001100
# the client now closes the connection; although its
11011101
# TLS shutdown fails on the corrupted record, it must
1102-
# still send close_notify, completing our unwrap()
1102+
# still send close_notify, on which recv() returns b''.
1103+
# Wait for it before sending ours: unwrap() right away
1104+
# would send close_notify to a peer that is about to
1105+
# close its socket, which turns that close into a TCP
1106+
# reset, and on Windows a reset discards the client's
1107+
# close_notify that is still unread (gh-158646).
1108+
sock.recv(1)
1109+
# recv() also returns b'' on a ragged EOF, i.e. without
1110+
# close_notify, but then unwrap() fails with an SSLError.
11031111
sock.unwrap()
11041112
except ssl.SSLError as exc:
11051113
server_err = exc
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a race in ``test_asyncio.test_sslproto`` where the server side of
2+
``test_shutdown_corrupted_ssl_sends_close_notify`` could fail with a
3+
connection reset on Windows.

0 commit comments

Comments
 (0)