Repository navigation
Description
Found by the adversarial review of #1630 (#1627). Adjacent to #1627 and #1631, and not fixed by either.
Mechanism
A request relayed to an H2 backend is encoded by that backend connection's write pass: kawa.prepare pops the request's StatusLine/Header/Flags blocks out of stream.front.blocks and leaves HEADERS/CONTINUATION frames in stream.front.out. Those frames carry the stream id of that backend connection and field blocks HPACK-encoded against that connection's encoder.
The request counts as sent only once Kawa::consume moves a byte (kawa.consumed). When the first write of the request takes 0 bytes, the stream is parked (expect_write) with front.out full and front.consumed == false.
If the backend connection then goes away, two paths treat the request as untouched and link the stream to a fresh backend:
end_stream_decision(lib/src/protocol/mux/shared.rs) answersEndStreamAction::Reconnecton!stream.front.consumed, andConnectionH2::end_stream'sReconnectarm (lib/src/protocol/mux/h2.rs) setsStreamState::Linkand queues the stream inpending_links;ConnectionH2::handle_goaway_frame(lib/src/protocol/mux/h2.rs) re-links every stream abovelast_stream_idwhosefront.consumedis false.
Neither path clears front.out or restores the popped blocks, and ConnectionH2::start_stream does not either. The new backend connection's write pass then transmits the stale frames first.
Scenario
- An H2 backend connection is established. Its socket is full, for example behind another stream's upload.
- A client request is linked to it. The write pass encodes its HEADERS and parks the stream: the write took 0 bytes.
- The backend closes the connection, or sends GOAWAY with a
last_stream_idbelow the stream. - The stream is re-linked to a new H2 backend connection.
Effect (by code reading, no reproduction yet)
The new backend connection receives:
- a HEADERS frame on the OLD connection's stream id, which the new connection never opened;
- a field block encoded against the OLD encoder's dynamic table, so its dynamic indexes resolve to nothing, or to other entries on the new decoder.
The request's own header blocks are gone from front.blocks, so the new connection cannot re-encode them, and its own stream id for the request never receives a HEADERS frame.
The likely outcomes are COMPRESSION_ERROR or PROTOCOL_ERROR on the new backend connection, which takes down every stream it carries, or a request carrying wrong fields.
H1 backends are not affected the same way: the H1 converter's output is protocol-level bytes that a fresh H1 connection can send as they are.
Options
- Treat a front that has been prepared (
!front.out.is_empty(), or blocks already popped) as consumed for H2 backends. The stream then gets the non-retry outcome, 502 or RST(REFUSED_STREAM), instead ofReconnect. - Keep the request's un-encoded blocks until the HEADERS frame has started on the wire. That is the send-time encoding shape of hyperium/h2's
FramedWrite::buffer.
Either needs a connection-level test with an H2 backend, a 0-byte first write, and a close or GOAWAY.
Activity
fix(mux-h2): encode a field block only once it is queued whole
FlorentinDUBOIS commentedon Sep 27, 2026
A worse variant than the one described above, found while reviewing #1630.
Router::connect(lib/src/protocol/mux/router.rs) links a stream to an existingConnected, non-draining H2 backend connection of the same cluster before it considers opening a new one, picking the one with the fewest active streams. That connection is usually already shared with other clients' streams, and its HPACK decoder state was built by its encoder, not by the one that encoded the stale block.When the re-linked stream's stale HEADERS frame goes out on that shared connection:
x-api-keyorauthorization-like custom header) — a cross-client field substitution, with no error;Both outcomes come from the same root cause: the request's un-encoded blocks were consumed by
kawa.prepareon the first connection, andfront.outstill holds frames bound to that connection's stream id and encoder when the stream is re-linked.fix(mux-h2): reset the HPACK encoder table when an encoded block is d…
fix(mux-h2): never re-link a request encoded for another H2 backend c…
FlorentinDUBOIS commentedon Sep 28, 2026
Scope correction:
Router, and with it every backend connection inRouter::backends, belongs to a singleMuxsession (fieldMux::router,lib/src/protocol/mux/mod.rs). An H2 backend connection is therefore shared only by the streams of one frontend connection, never between distinct client TCP connections. Any cross-user impact requires an intermediary (a CDN or load balancer, for example) that multiplexes several users over one frontend connection to sozu.For this issue: the re-link can only reach another backend connection of the same session. The stale field block is then decoded against a table built by that session's other streams, so the substitution described above happens between streams of one frontend connection: requests of the same client, or of different users behind the same intermediary.
fix(mux): end a Content-Length response truncated by a backend close …
fix(mux-h2): give back the send credit of DATA prepared and dropped u…
fix(mux-h2): never re-link a request encoded for another H2 backend c…
fix(mux-h2): never re-link a request encoded for another H2 backend c…
fix(mux-h2): never re-link a request encoded for another H2 backend c…
fix(mux-h2): never re-link a request encoded for another H2 backend c…
docs: document the hot-path zero-copy and syscall campaign and refres…
docs: document the hot-path zero-copy and syscall campaign and refres…
docs: document the hot-path zero-copy and syscall campaign and refres…
fix(mux): release the reservation of a dial abandoned after connect (#…