From 33ab725f60d580fef68c7976034d4015c936d9fc Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 21 Jan 2026 03:01:06 +0900 Subject: [PATCH] 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. --- crates/stdlib/src/ssl.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/stdlib/src/ssl.rs b/crates/stdlib/src/ssl.rs index 0ead7244bc..959525d1f1 100644 --- a/crates/stdlib/src/ssl.rs +++ b/crates/stdlib/src/ssl.rs @@ -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; } }