Repository navigation
Description
Summary
The connection-level send window of an H2 connection is debited when DATA frames are prepared (kawa.prepare), not when they reach the wire. When a stream holding prepared, unsent DATA frames is removed, those frames are dropped, but nothing gives the credit back. The peer never received those bytes, so it never returns them with a WINDOW_UPDATE either (RFC 9113 §6.9.1: the window accounts for DATA frames that were sent). The connection window therefore shrinks permanently, once for every such removal. On a backend connection that the router shares between clients, the window can eventually reach zero, at which point every request body on that connection stalls.
Observed on 6eef0ba1, by code reading; no reproduction test yet.
Mechanism
- In the
H2WritePhase::Preparearm ofConnectionH2::poll_write_target(lib/src/protocol/mux/h2.rs), the pass encodes up towindow = min(stream window, connection window)bytes of DATA intokawa.out. It then debits both windows for what was encoded (pass.consumed):*parts.windowandself.flow_control.consume_send_window(pass.consumed)(H2FlowControl::consume_send_window,lib/src/protocol/mux/h2_flow_control.rs). No byte has been written at that point. - When the socket takes 0 bytes, the pass parks the stream (
expect_write) with those frames still inkawa.out. When it takes part of a frame, only the rest of that one frame is adopted into the ordered output (H2Output::adopt_tail); the whole frames behind it stay inkawa.out. - If the stream is removed while parked, the frames still in its
kawa.outare never sent. Removal can come fromConnectionH2::end_stream(client cancel, backend timeout), a peer RST_STREAM (ConnectionH2::handle_rst_stream_frame),ConnectionH2::cancel_timed_out_streams,prune_inactive_streams_while_closing, or a stream recycled or reused afterwards. The same applies whenforcefully_terminate_answeror a default answer clears the parked queue. ConnectionH2::remove_dead_streamand the paths above never credit the connection window back.H2FlowControlhas no refund operation; its window only grows throughapply_window_update.- The peer sends WINDOW_UPDATE only for DATA it received. Credit for DATA that never left is therefore lost for the lifetime of the connection.
Scenario (backend connection, Position::Client)
- One H2 backend connection carries the uploads of several clients (
Router::connectmultiplexes them), with the default 65 535-byte connection window. - The backend reads slowly, so the socket buffer fills. A client's request body is prepared as DATA (for example 16 KiB, which debits the connection window by 16 KiB), the write takes 0 bytes, and the stream is parked.
- That client gives up (browser navigation, fetch abort) or the stream times out. The stream is removed and its prepared DATA is dropped unsent.
- The 16 KiB are never credited back. After roughly four such cancellations the connection window is 0, and every other stream's body on this connection waits for a WINDOW_UPDATE that the backend will never send for bytes it never got. The flow-control-stall reaper then cancels those streams too, with no fault on their side.
The frontend position has the same shape, with response DATA toward the client, but there the damage stays within one client's own connection.
Expected
The connection (and stream) window accounts only for DATA that reached the wire, or is credited back for prepared DATA that is dropped. Options:
- Credit
H2FlowControlback with the DATA payload bytes still queued in a stream'skawa.outwhen that queue is dropped. The frame headers are already walked on a park (h2_transmit::holds_header_frame), so the same walk can sum the DATA lengths. Every site that removes a parked stream or clears its queue would need the refund. - Or debit the window at transmit time (
h2_transmit::confirm) instead of prepare time (send-time accounting).
A regression test would need an H2 backend connection with a paced socket (0-byte first write), a DATA frame prepared and parked, the stream removed, and an assertion that flow_control.window() is back to its value before the prepare.
Activity
fix(mux-h2): give back the send credit of DATA prepared and dropped u…
fix(mux-h2): give back the send credit of DATA prepared and dropped u…
fix(mux-h2): give back the send credit of DATA prepared and dropped u…