Drain the socket before closing a TLS connection (#2673)

Server::process_and_close_socket() half-closes the socket and drains what
the peer is still sending before the final close (#2534), so that a close
with unread data, or with bytes still in flight, is not answered with a
RST. A RST can make the peer's stack discard a response it has received
but not yet read, as Windows does.

SSLServer::process_and_close_socket() still closed outright. After a
completed handshake, shut down TLS as before (sending close_notify when
the exchange completed) and then drain the same way. A failed handshake
closes outright as before.

Fix #2672
This commit is contained in:
Graeme Smecher authored and GitHub committed 2026-11-16 23:53:56 -05:00
1 parent 4af42e1907
commit d7b0d4bedb
1 file changed
+6 -2
+6 -2
View File
@@ -19160,8 +19160,12 @@ inline bool SSLServer::process_and_close_socket(socket_t sock) {
auto cleanup = detail::scope_exit([&] { auto cleanup = detail::scope_exit([&] {
if (handshake_done) { shutdown(session, !websocket_upgraded && ret); } if (handshake_done) { shutdown(session, !websocket_upgraded && ret); }
free_session(session); free_session(session);
detail::shutdown_socket(sock); if (handshake_done) {
detail::close_socket(sock); detail::drain_and_close_socket(sock);
} else {
detail::shutdown_socket(sock);
detail::close_socket(sock);
}
}); });
// Perform TLS accept handshake with timeout // Perform TLS accept handshake with timeout