Repository navigation
Description
Summary
When an H2 stream is removed while it is the target of a partially read DATA payload, expect_read is nulled without any state transition. The connection stays in H2State::Frame(header) with expect_read == None, and every later readable() pass returns at the expect_read() == None early exit without reading the socket. The connection reads nothing more (remaining payload, PING, new HEADERS) until its connection-level timeout fires. Other streams multiplexed on that connection stall with it.
Observed on origin/main at 4d104b3a0324acca3c18624a41f938d6f9070b16.
Cause
lib/src/protocol/mux/h2.rs:1951-2020: only a DATA frame on an existing stream setsexpect_read = Some((H2StreamId::Other { gid, .. }, payload_len)), so its payload goes straight into the stream buffer.lib/src/protocol/mux/h2.rs:4662-4800(cancel_timed_out_streams, called at the start ofpoll_read_targetand fromMux::timeout) and the reset paths callremove_dead_stream(h2.rs:3656).lib/src/protocol/mux/h2_stream_table.rs:293-300(H2StreamTable::remove) then setsexpect_read = Nonewhen it names the removedgid. The state staysFrame(header)and nothing records the unread remainder of the payload.lib/src/protocol/mux/h2.rs:2386-2389: every later pass takes theNonebranch. The only setters that later turnexpect_readback intoSomeare the post-read dispatch and the handshake arms (h2.rs:4284,h2.rs:4293). None of them runs inFramestate, so the connection stays wedged.
A second form of the same bug hits a stream parked on buffer pressure (h2.rs:2413 removes READABLE interest). Once that stream is reaped, try_resume_reading (h2.rs:4610-4632) cannot re-enable READABLE, because it only handles expect_read == Some((Other, _)). For example, a slow backend holds a frontend upload that is parked mid-DATA until stream_idle_timeout reaps it. This second form is inferred from the code and has not been reproduced.
This is not an edge-triggered readiness loss. The reproduction below re-inserts both the READABLE event and the READABLE interest before every pass, and the connection still makes no progress.
Reproduction
Unit test in lib/src/protocol/mux/h2.rs mod tests, which uses the existing test_h2_connection loopback helper:
- The server connection is in
H2State::Header. The peer sends HEADERS for stream 1 (END_HEADERS, no END_STREAM), then a DATA header announcing 10 bytes, followed by only 4 payload bytes. readable()runs untilexpect_read == Some((Other { .. }, 6)).context.nowmoves paststream_idle_timeout(30 s), and the peer sends the remaining 6 bytes plus a PING.readable()runs 64 times, witheventandinterestREADABLE re-inserted before each pass.
Result: the stream is reaped (H2::IdleTimeout access log), and after that the connection never reads again:
after the reap the connection must still read the PING and queue its ACK; state=Frame(FrameHeader { payload_len: 10, frame_type: Data, flags: 0, stream_id: 1 }) expect_read=None stuck_passes=64
Fix direction (not implemented)
Fix this at the remove_dead_stream chokepoint, not at h2.rs:2387. That early return keeps readable() from spinning. When the removed gid is the current expect_read target with n > 0 bytes still unread, the connection has to consume those n bytes, for example through H2State::Discard with Some((Zero, n)), the way refuse_stream_and_discard (h2.rs:4945-4960) does. It must also credit the frame's full payload_len to connection-level flow control, as handle_data_frame's unknown-stream branch (h2.rs:5700-5716) does. Discard credits nothing today, because it exists for refused HEADERS.
The zero buffer's available space also needs a decision: refuse_stream_and_discard sends goaway(EnhanceYourCalm) when the payload does not fit (h2.rs:2256).
Activity
fix(mux-h2): flush the backend end_stream RST before reading a header
fix(mux-h2): read nothing into zero while it holds unflushed output
fix(mux-h2): keep reading after a stream is reaped mid DATA payload
fix(mux-h2): keep reading after a stream is reaped mid DATA payload (s…