Skip to content

mux-h2: a PING or SETTINGS ACK is flushed inside a half-written stream frame #1600

Closed

Description

@FlorentinDUBOIS

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 (or front.out), not in zero. When the socket takes only part of it, the write pass parks the stream: set_expect_write(Some(H2StreamId::Other { .. })) in poll_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_frame serialises the ACK into zero and unconditionally sets expect_write = Some(Zero) (h2.rs:6522); the SETTINGS ACK does the same (h2.rs:6481). That overwrites the stream's park.
  • The next writable() runs control_flush_from, whose first stage flushes zero as soon as expect_write == Some(Zero) (h2.rs:4055). The 17 ACK bytes go out right after the first half of the stream frame.
  • With expect_write back to None, poll_write_target starts 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

Activity

  1. added 2 commits that reference this issue on Sep 26, 2026
    0b1f713
    b13175d
  2. added a commit that references this issue on Sep 27, 2026
    b03ffa2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions