Skip to content

fix(mux-h2): keep one stream send window per connection - #1757

Merged
FlorentinDUBOIS merged 4 commits into
mainfrom
fix/h2-per-leg-stream-window
Oct 2, 2026
Merged

FlorentinDUBOIS merged 4 commits into
mainfrom
fix/h2-per-leg-stream-window

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

RFC 9113 §6.9 flow control is per connection. A stream relayed from an H2 frontend to an H2 backend kept a single send window for both, so a client and a backend that each advertise SETTINGS_INITIAL_WINDOW_SIZE = 2^31-1 overflowed it (§6.9.2) and the backend connection was closed with GOAWAY(PROTOCOL_ERROR). The backend leg also started at the frontend's window, and each peer's WINDOW_UPDATE credited both legs.

  • Stream::window becomes Stream::front_window and Stream::back_window.
  • Stream::split and the new Stream::send_window_mut select the connection's own leg from its Position; SETTINGS and WINDOW_UPDATE handling use it.
  • ConnectionH2::start_stream sizes the backend leg from the backend's SETTINGS_INITIAL_WINDOW_SIZE.
  • H1 legs are unchanged.

Tests: unit a_backend_max_initial_window_is_independent_of_the_frontend_window, a_backend_stream_window_is_sized_and_credited_by_the_backend_only, a_frontend_window_update_credits_the_frontend_leg_only; e2e test_h2_client_and_h2_backend_both_at_max_initial_window. Docs and CHANGELOG updated.

Fixes #1755

RFC 9113 §6.9 flow control is per hop, but a stream relayed from an H2
frontend to an H2 backend kept one send window for both connections.
A client and a backend both advertising SETTINGS_INITIAL_WINDOW_SIZE
= 2^31-1 overflowed it and the backend connection was closed with
GOAWAY(PROTOCOL_ERROR); the backend leg also started at the frontend's
window, and each peer's WINDOW_UPDATE credited the other leg.

Split Stream::window into front_window and back_window. Stream::split
and the new Stream::send_window_mut select the connection's own leg
from its Position, and ConnectionH2::start_stream sizes the backend
leg from the backend's initial window. H1 legs are unchanged.

Fixes #1755

Signed-off-by: Florentin Dubois <[email protected]>
a_backend_stream_answered_before_its_request_was_written_is_cancelled,
added with #1741, withholds the backend's send window by setting
Stream::window to 0. This branch splits that field into front_window and
back_window, one per connection (RFC 9113 section 6.9), so after main was
merged in the test no longer compiled: the two changes touched different
lines and merged without a textual conflict.

The test drives the stream on its backend connection, whose send window
is now back_window (Stream::send_window_mut picks the leg from the
connection's Position). Set that leg to 0 so the request body still waits
behind its HEADERS, as the test intends.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit fac8214 into main Oct 2, 2026
22 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Oct 2, 2026
…#1782)

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



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-h2): a relayed stream shares one send window between its frontend and backend connections

1 participant