Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 18, 2026

Summary by CodeRabbit

  • Improvements
    • SSL socket shutdown behavior enhanced: read and write operations now only error after shutdown is fully completed, rather than blocking during intermediate shutdown states, providing more predictable behavior during connection closure
    • SSL sockets now automatically clean up and release internal resources when disposed, preventing potential resource leaks and improving system stability and memory efficiency

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

A Drop implementation was added to PySSLSocket for resource cleanup upon drop, and shutdown behavior was modified so reads and writes error only after shutdown completion rather than blocking during state transitions.

Changes

Cohort / File(s) Summary
SSL Socket Resource Management & Shutdown
crates/stdlib/src/ssl.rs
Added Drop trait implementation for PySSLSocket to clear connection state, pending TLS output, write buffering length, and reset shutdown state. Modified shutdown behavior to only error reads/writes after Completed state instead of blocking on any non-NotStarted state during transitions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through SSL's den,
With Drop to clean up now and then,
No leaks remain, no state astray,
Resources freed—hip-hop, hooray! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Drop for PySSLSocket' accurately describes the main change: implementing a Drop trait for the PySSLSocket type to handle resource cleanup.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone youknowone marked this pull request as ready for review January 19, 2026 00:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/stdlib/src/ssl.rs (1)

3679-3688: Block writes once shutdown has started.
After close_notify is sent, sending application data violates TLS. The current check allows writes during SentCloseNotify. Consider blocking any write once shutdown is initiated.

🐛 Proposed fix
-            if *self.shutdown_state.lock() == ShutdownState::Completed {
+            let shutdown_state = *self.shutdown_state.lock();
+            if shutdown_state != ShutdownState::NotStarted {
                 return Err(vm
                     .new_os_subtype_error(
                         PySSLError::class(&vm.ctx).to_owned(),
                         None,
                         "cannot write after shutdown",
                     )
                     .upcast());
             }

@youknowone youknowone merged commit 6a064aa into RustPython:main Jan 19, 2026
13 checks passed
@youknowone youknowone deleted the ssl-drop branch January 19, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant