flush on WantWrite by youknowone · Pull Request #6717 · RustPython/RustPython
📝 Walkthrough
Walkthrough
The SSL handshake logic in compat.rs is enhanced to more thoroughly drain the rustls write buffer when WantWrite occurs during socket mode, and to explicitly flush all pending TLS data after handshake completion in non-BIO mode.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
SSL Handshake Buffer Flushing crates/stdlib/src/ssl/compat.rs |
Modified handle_handshake_complete to loop and drain entire rustls write buffer on WantWrite instead of breaking early; added explicit flush of pending TLS data after handshake completion in non-BIO mode to ensure delivery to peer |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
- Fix SSL handshake partial send #6635: Modifies SSL handshake write/flush logic in
ssl/compat.rsto ensure rustls-generated TLS bytes are fully drained with WantWrite handling. - Share more ssl consts and fix openssl #6462: Changes TLS write-flushing and handshake read/write behavior in
ssl/compat.rsthrough explicit flush/EOF handling and draining pending rustls writes.
Poem
🐰 The buffers flow like morning dew,
No data left behind in queue,
Loop and drain with gentle care,
Flush it all, both here and there! 💫
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'flush on WantWrite' is directly related to the main change, which involves flushing the rustls write buffer when a WantWrite error occurs during the SSL handshake. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/stdlib/src/ssl/compat.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/stdlib/src/ssl/compat.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (windows-2025)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
🔇 Additional comments (1)
crates/stdlib/src/ssl/compat.rs (1)
1240-1268: The WantWrite handling logic is correct and properly implements buffer draining with timeout protection.The approach of catching
WantWrite, performing a blocking flush, and continuing the loop ensures all TLS handshake data reaches the peer. Theblocking_flush_all_pendingimplementation provides:
- Timeout handling: Respects socket timeout via
sock_selectand returns timeout errors- Error resilience: Retries on transient blocking IO errors, returns on real errors
- Bounded execution: Loops only while pending data exists, avoiding infinite loops
- Edge case handling: Handles
sent == 0case where socket wasn't ready despite selectThe data flow is correct:
send_all_bytesbuffers unsent data inpending_tls_outputonWantWriteblocking_flush_all_pendingblocks until that buffer is emptied (with timeout safeguard)- Loop continues to drain remaining rustls buffer
- Final flush after loop handles any edge cases
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.
Comment @coderabbitai help to get the list of available commands and usage tips.