Skip to content

fix(mux-h1): clear end-of-stream flags on the keep-alive stream reset - #1782

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/h1-keep-alive-h2-backend-reuse
Oct 2, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/h1-keep-alive-h2-backend-reuse

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

With an H1 client in front of an H2 backend, the second request on a keep-alive client connection was answered 502. ConnectionH1::writable reused the client stream slot without clearing the end-of-stream flags and DATA counters that Context::create_stream clears for a recycled slot. The H2 backend connection then refused the second response's HEADERS as arriving on a closed stream (RFC 9113 §5.1) and sent GOAWAY(STREAM_CLOSED).

The keep-alive reset now clears them, and ConnectionH2::start_stream asserts (debug builds) that the backend leg is fresh. The backend leg's send window is sized from the backend's SETTINGS_INITIAL_WINDOW_SIZE since #1757: without it, a keep-alive request started from what the previous one left of the window, so large request bodies stalled, and a backend advertising less than 65 535 was over-run.

Tests, e2e/src/tests/tests.rs:

  • test_h1_to_h2_keep_alive_requests
  • test_h1_to_h2_keep_alive_requests_small_backend_window

Each sends a GET, four 600 000-byte POSTs and a GET on one client connection, and asserts one backend connection and six backend requests, with the default and a 16 384-byte backend window. Both fail without #1757: [true, false, …] with the small window, [true, true, true, false, …] with the default. The H2 mock backend now counts accepted connections and can advertise a stream window. Documented in lib/src/protocol/mux/LIFECYCLE.md §3.2 and CHANGELOG.md.

Fixes #1781

@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/h1-keep-alive-h2-backend-reuse branch from ab3ef0d to 2bfd353 Compare October 1, 2026 21:29
With an H1 client in front of an H2 backend, ConnectionH1::writable
reused the client stream slot for the next request without clearing
back_received_end_of_stream, front_received_end_of_stream and the
per-direction DATA counters, which Context::create_stream clears for a
recycled slot. The stale end-of-stream flag made the H2 backend
connection refuse the second response's HEADERS as arriving on a closed
stream (RFC 9113 section 5.1) and send GOAWAY(STREAM_CLOSED), so the
client got a 502.

The keep-alive reset now clears them.

Closes #1781

Signed-off-by: Florentin Dubois <[email protected]>
Cover a GET, four 600000-byte POSTs and a GET on one H1 client
connection over one H2 backend connection, with the default and a
16384-byte backend initial window: each request must start from the
backend's own window, which ConnectionH2::start_stream sizes, and the
backend must see one connection. The H2 mock backend counts accepted
connections and can advertise a stream window.

Assert in ConnectionH2::start_stream that the backend leg of a slot is
fresh, and name in LIFECYCLE.md section 3.2 exactly what the keep-alive
reset clears and what it leaves to create_stream's other paths.

Refs #1781

Signed-off-by: Florentin Dubois <[email protected]>
Without the keep-alive reset of the end-of-stream flag, a debug build
panics on the fresh-backend-leg assertion of start_stream before any
502; without the backend-leg window sizing, only the small-window
variant fails, at its fourth POST.

Refs #1781

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/h1-keep-alive-h2-backend-reuse branch from 15d4bbc to eb35f64 Compare October 2, 2026 01:41
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 97c7f4c into main Oct 2, 2026
28 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Oct 2, 2026
Brings in #1787 and #1782; the only conflicts were pinned h2.rs line
citations in doc/h2_mux_internals.md, repointed.

Also fixes the merged reset-stream handling:

- An empty DATA frame without END_STREAM on a stream this endpoint reset
  never reached handle_data_frame, so it skipped the empty-DATA flood
  counter (CVE-2019-9518) and fit any window allowance for free. The
  was_reset_locally branch now counts it toward that limit like a live
  stream does.
- The DATA and header-block allowances are held for at most 512 reset
  streams: a stream refused or reset untracked stays in rst_sent and
  never enters the ring its allowances are dropped with.
- The docs say "the stream's initial receive window", state how empty
  DATA counts, and note that a backend connection's allowances are
  bounded by the backend's own concurrency, not the emitted-RST cap.

Refs #1783

Signed-off-by: Florentin Dubois <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(mux-h1): second keep-alive request to an H2 backend answered 502

1 participant