Skip to content

Defer blocked control frame writes (#975) - #1003

Open
rleungx wants to merge 2 commits into
hyperium:masterfrom
rleungx:fix/bidirectional-control-backpressure-975
Open

rleungx wants to merge 2 commits into
hyperium:masterfrom
rleungx:fix/bidirectional-control-backpressure-975

Conversation

@rleungx

@rleungx rleungx commented Nov 10, 2026

Copy link
Copy Markdown

Bidirectional bulk transfers can deadlock when pending PONG, PING, or SETTINGS writes prevent both peers from reading. Queue control output behind DATA and CONTINUATION frames so reads can continue while the control queue has capacity.

Preserve control FIFO order and the frame-size limit for fragments preceding a SETTINGS ACK. Reuse writer-owned header scratch storage while keeping HPACK compression state separate and standalone frame encoding APIs available. The queue is bounded to 16 KiB and returns Pending at capacity, with no new connection-close condition.

Fixes #975.

Validation:

  • 726 tests passed, 14 ignored. Shared cases cover six blocked-control scenarios, partial writes, continuation limits, saturation/recovery, shutdown, and drop/borrow behavior.
  • All three connection regressions fail on the upstream baseline at their intended read-progress assertions.
  • Formatting, default/all-feature Clippy, all-feature compilation, and the fuzz interface passed.
  • The unchanged runtime code also passed actual Rust 1.63 production-library checks and h2spec (144 passed, one skipped). In the original 5 MiB TLS reproduction, the baseline stalled in 2 of 3 runs and the fix completed all 3; all 6 additional TLS runs completed.

Release measurements of the same runtime code on macOS arm64 with Rust 1.92 (8 interleaved base/head pairs; medians):

Workload Base Fix
16 KiB codec, ns/frame 27.897 27.922
64 B TCP, serial, requests/s 42,272 43,535
64 B TCP, concurrency 64, requests/s 153,121 156,271
1 MiB TCP, concurrency 16, requests/s 1,033.5 1,045.0

These samples did not detect a significant throughput or latency slowdown, but intervals permit small regressions. Linux x86_64 diagnostics measured about one extra instruction per 64-byte DATA frame (+0.25%) and 1.25–1.83% fewer instructions for 16 KiB frames. Client/server connection sizes remained 1,280 bytes on both platforms, with matching serial allocation counts. This does not establish universal zero overhead.

Bidirectional DATA transfers can deadlock when a pending control-frame
write prevents both peers from reading their sockets.

Queue bounded control output behind DATA and CONTINUATION frames.
Preserve FIFO order, pre-ACK frame-size limits, and Pending backpressure
when the queue is full. Reuse writer-owned scratch storage while keeping
HPACK compression state separate and standalone frame APIs available.

Validation: 726 tests passed, 14 ignored; refactored connection regressions
fail at their read-progress assertions on the upstream baseline.
Formatting, Clippy, all-feature and fuzz-interface checks pass. Runtime
logic is unchanged from the TLS/MSRV/h2spec and performance-validated
candidate; strict zero performance regression remains unverified.
Emit the existing codec debug event for controls queued behind blocked
writes. Share the client/server pending-poll helper without changing test
scenarios or assertions.

Signed-off-by: rleungx <[email protected]>

This branch has not been deployed

No deployments
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.

Connection deadlock under bidirectional bulk data: both peers stop reading while a PONG/PING/SETTINGS write is pending (poll_ready gates poll_next)

1 participant