Fix Drop to prevent TLS data loss (#6825)

Remove pending_tls_output.clear() from Drop implementation.

SSLSocket._real_close() in Python doesn't call shutdown() before
closing - it just sets _sslobj = None. This means pending TLS data
in the output buffer may not have been flushed to the socket yet.
Clearing this buffer in Drop causes data loss, resulting in empty
HTTP responses (test_socketserver failure on Windows).

The explicit clearing is also unnecessary since all struct fields
are automatically freed when the struct is dropped.
This commit is contained in:
Jeong, YunWon
2026-01-21 17:29:22 +09:00
committed by GitHub
parent 1b5deea53a
commit 2df879c5ee

View File

@@ -4406,15 +4406,14 @@ mod _ssl {
// Clean up SSL socket resources on drop
impl Drop for PySSLSocket {
fn drop(&mut self) {
// Clear connection state
// Only clear connection state.
// Do NOT clear pending_tls_output - it may contain data that hasn't
// been flushed to the socket yet. SSLSocket._real_close() in Python
// doesn't call shutdown(), so when the socket is closed, pending TLS
// data would be lost if we clear it here.
// All fields (Vec, primitives) are automatically freed when the
// struct is dropped, so explicit clearing is unnecessary.
let _ = self.connection.lock().take();
// Clear pending buffers
self.pending_tls_output.lock().clear();
*self.write_buffered_len.lock() = 0;
// Reset shutdown state
*self.shutdown_state.lock() = ShutdownState::NotStarted;
}
}