8000 Fix install ujson by youknowone · Pull Request #6502 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@youknowone
Copy link
Member
@youknowone youknowone commented Dec 25, 2025

close #6500
fix #6491

Summary by CodeRabbit

  • New Features

    • Added Timeout error type for explicit socket timeout handling.
  • Bug Fixes

    • Improved non-blocking socket timeout behavior and semantics.
    • Enhanced connection disconnection error handling.
    • Refined TLS buffer management and data processing logic.

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

@coderabbitai
Copy link
Contributor
coderabbitai bot commented Dec 25, 2025
📝 Walkthrough

Walkthrough

The changes enhance SSL read handling in non-blocking socket scenarios and timeout behavior, introducing retry logic for feeding TLS data to rustls, improved EOF/connection-closed detection, and a new Timeout error variant to distinguish socket read timeouts from other IO errors.

Changes

Cohort / File(s) Summary
SSL read and timeout handling
crates/stdlib/src/ssl/compat.rs
Modified ssl_read to add a data-driven retry flow for non-blocking sockets: zero-timeout sockets return WantRead immediately, while timed-out sockets attempt additional TLS data reads instead of erroring. Enhanced ssl_read_tls_records to handle cases where rustls cannot consume data due to a full buffer by processing existing packets and retrying. Changed ssl_ensure_data_available timeout semantics to return Timeout error instead of WantRead when a socket with timeout exceeds its time limit. Improved EOF/connection-closed detection by mapping ECONNABORTED/ECONNRESET to Eof. Simplified "buffer full" fallback path to defer plaintext consumption to main loop. Added clarifying comments for non-blocking vs. blocking behavior and timeout semantics. Introduced new public SslError::Timeout(String) variant.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 A hop, a skip, through timeout's trick,
Non-blocking reads that stick so quick,
Retry the dance, feed rustls once more,
ujson installs—no SSLWantRead's sore! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title 'Fix install ujson' is vague and does not accurately represent the actual changes, which are comprehensive SSL read handling improvements. Update title to reflect the main change, such as 'Fix SSL read handling for blocking sockets with timeout support' or similar.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully addresses the core requirements: fixes SSLWantReadError on blocking sockets (#6500, #6491), implements proper timeout handling, adds Timeout error variant, and adjusts SSL state machine interaction to prevent premature errors during streaming operations.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing SSL read handling for blocking sockets and streaming scenarios as specified in the linked issues; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 December 25, 2025 01:29
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

🧹 Nitpick comments (1)
crates/stdlib/src/ssl/compat.rs (1)

424-466: Core fix looks correct, but consider documenting the buffer size choice.

This retry logic properly handles the case where rustls reports it doesn't need more data but additional TLS records may still arrive from the network. The distinction between non-blocking (immediate return) and blocking/timeout sockets (attempt read) is correct.

Minor observations:

  • Line 439: The hardcoded 2048 buffer size is reasonable for TLS records but lacks explanation. Consider adding a comment explaining why this size was chosen (e.g., typical TLS record overhead + payload).
  • Line 449-453: The clone() and unwrap_or(0) are safe but slightly inefficient. The clone is necessary for try_into_value, and the unwrap_or provides a safe fallback if conversion fails.
💡 Optional: Add explanatory comment for buffer size
-    let data = match socket.sock_recv(2048, vm) {
+    // Read up to 2048 bytes (sufficient for typical TLS record: 5-byte header + up to ~16KB payload fragment)
+    let data = match socket.sock_recv(2048, vm) {
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebdc033 and 709ba76.

📒 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 running cargo fmt to format Rust code
Always run clippy to lint Rust 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
🧬 Code graph analysis (1)
crates/stdlib/src/ssl/compat.rs (2)
crates/stdlib/src/ssl.rs (2)
  • timeout (4165-4168)
  • e (1115-1115)
crates/stdlib/src/socket.rs (4)
  • timeout (707-709)
  • std (1538-1538)
  • std (1598-1598)
  • new (2446-2450)
⏰ 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). (1)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
🔇 Additional comments (4)
crates/stdlib/src/ssl/compat.rs (4)

399-399: LGTM: Timeout variant appropriately distinguishes timeout errors.

The new Timeout(String) variant properly separates socket timeout scenarios from generic IO errors and WantRead conditions, improving error clarity and matching Python's timeout exception semantics.


479-481: LGTM: Simplified fallback defers to main buffer handling.

The simplified continue is appropriate here since the primary buffer-full logic is now handled in ssl_read_tls_records (lines 569-585). This serves as a safety net fallback.


560-599: Excellent buffer-full handling with proper safeguards.

The enhanced retry logic correctly handles rustls buffer exhaustion:

  1. When read_tls returns 0, calls process_new_packets to consume buffered data and make room
  2. Retries once to feed remaining data
  3. Critical: Line 576-577 breaks if still can't consume, preventing infinite loops

The dual handling of Ok(0) and Err("buffer full") paths ensures robustness across different rustls error modes.


656-659: LGTM: Correct semantic distinction between timeout and would-block.

Changing from WantRead to Timeout when the socket times out during select is semantically correct. WantRead indicates a non-blocking socket would block, while Timeout indicates an operation exceeded its time limit. This properly aligns with Python's socket.timeout exception behavior.

@youknowone youknowone merged commit 5122aed into RustPython:main Dec 25, 2025
13 checks passed
@youknowone youknowone deleted the ssl-ujson branch December 25, 2025 01:32
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.

pip install ujson: pip._vendor.urllib3.exceptions.SSLError: The operation did not complete (read)

1 participant

0