Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix Drop to prevent TLS data loss
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.
  • Loading branch information
youknowone committed Jan 21, 2026
commit 33ab725f60d580fef68c7976034d4015c936d9fc
15 changes: 7 additions & 8 deletions crates/stdlib/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading