Skip to content

Commit 2df879c

Browse files
authored
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.
1 parent 1b5deea commit 2df879c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

crates/stdlib/src/ssl.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,15 +4406,14 @@ mod _ssl {
44064406
// Clean up SSL socket resources on drop
44074407
impl Drop for PySSLSocket {
44084408
fn drop(&mut self) {
4409-
// Clear connection state
4409+
// Only clear connection state.
4410+
// Do NOT clear pending_tls_output - it may contain data that hasn't
4411+
// been flushed to the socket yet. SSLSocket._real_close() in Python
4412+
// doesn't call shutdown(), so when the socket is closed, pending TLS
4413+
// data would be lost if we clear it here.
4414+
// All fields (Vec, primitives) are automatically freed when the
4415+
// struct is dropped, so explicit clearing is unnecessary.
44104416
let _ = self.connection.lock().take();
4411-
4412-
// Clear pending buffers
4413-
self.pending_tls_output.lock().clear();
4414-
*self.write_buffered_len.lock() = 0;
4415-
4416-
// Reset shutdown state
4417-
*self.shutdown_state.lock() = ShutdownState::NotStarted;
44184417
}
44194418
}
44204419

0 commit comments

Comments
 (0)