Skip to content

fix(client): fail parked h2 request with connection error on close - #4275

Merged
seanmonstar merged 1 commit into
hyperium:masterfrom
bunnysayzz:fix/h2-parked-dispatch-gone-4269
Nov 16, 2026
Merged

seanmonstar merged 1 commit into
hyperium:masterfrom
bunnysayzz:fix/h2-parked-dispatch-gone-4269

Conversation

@bunnysayzz

@bunnysayzz bunnysayzz commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

When the h2 connection goes away while a request is waiting for a stream to open, the parked callback was never failed. It fell through to Callback::drop, so the caller saw a DispatchGone user error instead of the connection error.

Fail the parked callback in the poll_ready error branch instead: canceled on a clean GOAWAY, the h2 reason otherwise. The original error is still returned from the task.

Adds a regression test with a server that allows one concurrent stream and closes while the second request is parked. The test fails before this change with User(DispatchGone) and passes after.

Fixes #4269

  • The description, docs, and comments (words meant for humans) are written by a human, not by an LLM.

When the h2 connection drops while a request is still waiting for a
stream slot, the parked callback was left to drop, and the caller got
a misleading DispatchGone user error. Fail it with the connection
error instead: canceled on a clean GOAWAY, the h2 reason otherwise.

Adds a regression test with a server that only allows one concurrent
stream and closes while the second request is parked.

Fixes hyperium#4269

@seanmonstar seanmonstar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@seanmonstar
seanmonstar merged commit dea9acb into hyperium:master Nov 16, 2026
24 of 25 checks passed
jimeh added a commit to jimeh/connectrpc-ruby that referenced this pull request Nov 24, 2026
…onnection end (#211)

* fix(hyper): adopt hyper 1.13.0, which drains its request channel at connection end

hyper 1.13.0 fixes hyperium/hyper#4202, the tokio send race behind #208:
its HTTP/1.1 and HTTP/2 dispatchers now close and drain their request
channel before the connection future completes (hyperium/hyper#4222,
#4242). It is adopted one day after release under a one-off exception to
the 7-day crate age rule, recorded in the plan's D16, after checking that
the published crate matches the v1.13.0 tag and reading the 1.12.0..1.13.0
diff. Only hyper moves in the lock; the requirement floor follows it.

hyper 1.13.0 also fails a request waiting for an HTTP/2 stream slot with
the bare code of its connection's error (hyperium/hyper#4275), which the
transport classified as a stream reset: gRPC `internal` or "stream reset"
where the connection's other streams, and 1.12, reported a closed
connection. A bare h2 code is now a connection failure, as h2 and grpc-go
report one. A raw-peer spec fails the connection with DATA on stream 0
while a call waits for the slot.

The stranded-request guard from #210 stays as a safety net for futures
dropped unfinished; its comments, the README and the plan say what 1.13.0
now covers.

* docs(hyper): qualify what hyper 1.13.0 drains and when a parked request gets a bare code

An HTTP/1.1 upgrade completes without the channel drain, so the stranded
guard still covers it alongside futures dropped unfinished. Only a
connection error with a code other than NO_ERROR reaches a request waiting
for a stream slot as a bare code; a graceful close and a keepalive timeout
still read as a closed connection. The classification comment names the
two other bare codes it also counts, and the new spec notes the dispatch
gap it cannot rule out. The reproducer counts stay in the pull request.

* docs(hyper): name every upgrade trigger and parked-request branch

hyper's HTTP/1.1 client also upgrades on a 2xx reply to CONNECT, and an
error without a code reaches a parked request as a cancellation. The
CONNECT reset comment states hyper's exact condition, and the spec comment
covers the whole window before hyper parks the request.

* docs(hyper): narrow the upgrade, early-answer and spec-window wording

A 204 reply to CONNECT is not an upgrade. hyper answers a request waiting
for a slot early only when its dispatch finds the connection failed and
keepalive has not timed out, and the spec's gap ends when the readiness
poll checks for the connection error.

* docs(hyper): record hyper 1.13.0 in the support profile and clarify failure docs

The support profile's tested lock now names hyper 1.13.0. `reset_code`
also carries a GOAWAY code h2 sent itself, as it already did, so its docs
no longer say "received". The plan gives each parked-request outcome its
own clause, and the README names the cases that can still strand a request.

* test(hyper): park the queued call before corrupting its connection

The stream-slot spec sent the corrupt frame after request:indexed, which
fires before hyper's dispatch calls h2's send_request and parks the
request; h2 processing the frame in that gap would fail the call through
h2's GOAWAY error, which reads the same, so a pass could skip the slot
path. A dispatch:returned:N hold point, counted when hyper's HTTP/2
connection future returns pending with N stream indexes taken, shows the
poll that passed the queued call to h2 has ended. The spec now waits for
it. It costs one atomic load per pending poll when nothing is armed.

* docs(hyper): say when reset_code and dispatch:returned hold

reset_code can carry a code h2 fails the connection with before h2
writes its own GOAWAY, and only the first dispatch:returned:N return
after request N was indexed shows that request parked.
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.

h2 client: request pending stream open is dropped with DispatchGone when the connection closes

2 participants