Skip to content

Patch tonic, hyper and h2 to survive HTTP/2 GOAWAY - #8

Open
arianvp wants to merge 4 commits into
mainfrom
claude/epic-franklin-vwgzay
Open

arianvp wants to merge 4 commits into
mainfrom
claude/epic-franklin-vwgzay

Conversation

@arianvp

@arianvp arianvp commented Oct 15, 2026

Copy link
Copy Markdown
Owner

L7 load balancers such as nginx and AWS ALB recycle HTTP/2 connections
by sending a graceful GOAWAY (NO_ERROR) after a number of requests.
Requests the proxy did not accept were never processed and are safe to
retry on a new connection, but tonic fails them instead: with
Canceled: connection closed when they were still queued in hyper's
dispatch channel, or with h2 protocol error: http2 error
(GoAway NO_ERROR) for streams above the GOAWAY's last stream ID. Builds
against a remote cache or RBE behind such a proxy fail, typically while
materializing outputs (meta#1294).

Patch the transport to handle them like grpc-go does (gRFC A6
transparent retries, and the GOAWAY section of PROTOCOL-HTTP2.md):

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01NBCkPZ5aLoM73ujG2GyuHA

L7 load balancers such as nginx and AWS ALB recycle HTTP/2 connections
by sending a graceful GOAWAY (NO_ERROR) after a number of requests.
Requests the proxy did not accept were never processed and are safe to
retry on a new connection, but tonic fails them instead: with
`Canceled: connection closed` when they were still queued in hyper's
dispatch channel, or with `h2 protocol error: http2 error`
(GoAway NO_ERROR) for streams above the GOAWAY's last stream ID. Builds
against a remote cache or RBE behind such a proxy fail, typically while
materializing outputs (meta#1294).

Patch the transport to handle them like grpc-go does (gRFC A6
transparent retries, and the GOAWAY section of PROTOCOL-HTTP2.md):

- tonic: arianvp/tonic goaway-0.14.6-buck2, the tonic 0.14.6 + IPv6/TLS
  commit buck2 already pinned, plus edef's GoawayRetry layer from
  edef1c/tonic (see grpc/grpc-rust#2185), reworked to follow grpc-go. A
  request that never left the client is sent again. A request the server
  refused, with a GOAWAY or REFUSED_STREAM, is sent again once if it was
  the first attempt and its body still fits in the 256 KiB kept for a
  replay. A refused request that isn't retried fails with UNAVAILABLE
  instead of INTERNAL, so buck2's own `retry` takes over. Like grpc-go,
  a new connection opens no streams before the server's SETTINGS arrive,
  so the retries don't overrun its MAX_CONCURRENT_STREAMS.
- hyper: arianvp/hyper protocol-nack-1.12.0, hyper 1.12.0 plus
  Error::is_protocol_nack(), which tells tonic that the server refused a
  request (hyperium/hyper#4052 reworked as its review suggested), and a
  fix for requests the connection task dropped with DispatchGone while
  they waited for their stream to open when the connection shut down.
  1.12.0 also fixes hyperium/hyper#4195, the hop-by-hop header
  regression buck2 downgraded from 1.11.1 for.
- h2: hyperium/h2 master, i.e. 0.4.20 plus hyperium/h2#977, which keeps
  a response whose END_STREAM had arrived when the connection hit a
  GOAWAY or EOF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBCkPZ5aLoM73ujG2GyuHA
A trimmed down version of arianvp/buck2-grpc-reproducer: bazel-remote
behind an nginx gRPC proxy that sends GOAWAY every 100 requests, and
1100 actions, 100 of them with 512 KiB outputs, built once with an
empty cache and once more from it. It needs no prelude.

test.sh fails if either build fails, if any action of the second build
was not a cache hit (a failed upload or lookup doesn't fail the build,
it just shows up as a local run), or if nginx never sent a GOAWAY.

Run it in the Linux build-and-test job with the debug binary, using
bazel-remote's release binary and the runner's nginx. Before the
previous commit it fails every time with errors like

    Failed to make BatchReadBlobs request: code: 'Internal error', message: "h2 protocol error: http2 error",
    source: tonic::transport::Error(Transport, hyper::Error(Http2, Error { kind: GoAway(b"", NO_ERROR, Remote) }))

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBCkPZ5aLoM73ujG2GyuHA
The patched tonic retries a request refused by a GOAWAY only if its body
fits in the 256 KiB it keeps for a replay. A larger upload fails with
UNAVAILABLE instead, and `retry` in `upload_impl` has to retry it.

Test this for BatchUpdateBlobs and ByteStream.Write: a fake server
refuses a 512 KiB upload after receiving more than 256 KiB of it, and
the upload must then succeed on a new connection. On its first
connection, the server speaks just enough HTTP/2 to do that, because
h2's server can't refuse a request it has started receiving. Later
connections use h2.

If tonic reports the refusal as INTERNAL, as upstream tonic does,
`retry` doesn't retry it and both tests fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBCkPZ5aLoM73ujG2GyuHA
This reverts commit 3a643c7, which made `retry` treat CANCELLED as
transient so that requests failing with

    hyper::Error(Canceled, "connection closed")

were sent again. hyper reports that for a request that was still waiting
to be sent when its connection closed, typically after a proxy recycled
the connection with a GOAWAY. The patched tonic now sends such a request
again by itself, on a new connection, so it no longer reaches `retry`.
The nginx GOAWAY example passes without it.

The client sets no deadlines, so CANCELLED can still come only from a
server resetting a stream with CANCEL, or from a request whose
connection closed before it could be sent, 16 times in a row. Those now
fail instead of being retried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBCkPZ5aLoM73ujG2GyuHA
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.

Automatically disabled keep-alive destroys hop-by-hop headers

2 participants