Repository navigation
Description
Summary
A PING or SETTINGS acknowledgement received while a stream frame (HEADERS or DATA) is half-written is flushed inside that frame. The peer then reads a corrupt frame stream.
Mechanism (origin/main bbceca828ce965469e2a39b490a2f4b00a9f67fd)
- A stream frame lives in the stream's own
back.out(orfront.out), not inzero. When the socket takes only part of it, the write pass parks the stream:set_expect_write(Some(H2StreamId::Other { .. }))inpoll_write_target(lib/src/protocol/mux/h2.rs:3251, and the resume arm keeps the park on a second stall,h2.rs:2948). The next pass resumes exactly that stream (h2.rs:2870). - READABLE is not withdrawn by that park, so the peer's next frame is still read.
handle_ping_frameserialises the ACK intozeroand unconditionally setsexpect_write = Some(Zero)(h2.rs:6522); the SETTINGS ACK does the same (h2.rs:6481). That overwrites the stream's park.- The next
writable()runscontrol_flush_from, whose first stage flusheszeroas soon asexpect_write == Some(Zero)(h2.rs:4055). The 17 ACK bytes go out right after the first half of the stream frame. - With
expect_writeback toNone,poll_write_targetstarts a fresh scheduler pass, which emits the rest of the stream frame after the ACK.
WINDOW_UPDATE and RST_STREAM drains are not affected: they are gated on expect_write().is_none() (h2.rs:4096, h2.rs:4144).
Reproduction
A unit test with a socket that takes 20 bytes of a 41-byte DATA frame on stream 1, then answers WouldBlock; the peer then sends a PING; the socket is then unthrottled. Parsing the bytes the socket took, as the peer would:
left: Err("frame type 0x64 announces 6579300 bytes, 8 remain")
i.e. 20 DATA bytes, the 17-byte PING ACK, then the remaining 21 DATA bytes.
Expected
As in HAProxy, whose ACKs are appended to the tail of the single mux output ring (h2c_send_ping, h2c_ack_settings in src/mux_h2.c) and therefore always follow the frame being sent, an ACK must wait for the half-written frame to complete before it is flushed.
Related, not covered here
end_stream's RST_STREAM(CANCEL) written intozerohas the same exposure; fix(mux-h2): keep reading after a stream is reaped mid DATA payload #1599 addresses it (zero_takes_output).goaway()also setsexpect_write = Some(Zero)without checking for a parked stream (h2.rs:5173).
Activity
fix(mux-h2): send a PING or SETTINGS ACK after a half-written stream …
fix(mux-h2): keep reads and GOAWAYs off zero while it holds output
fix(mux-h2): keep reading after a stream is reaped mid DATA payload
fix(mux-h2): send a PING or SETTINGS ACK after a half-written stream …