Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 closedwhen they were still queued in hyper'sdispatch 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):
commit buck2 already pinned, plus edef's GoawayRetry layer from
edef1c/tonic (see GoAway are not handled properly by grpc client in reconnect.rs 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
retrytakes 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.
Error::is_protocol_nack(), which tells tonic that the server refused a
request (feat(error): add h2_go_away_reason() to expose GOAWAY reason code 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 Automatically disabled keep-alive destroys hop-by-hop headers hyperium/hyper#4195, the hop-by-hop header
regression buck2 downgraded from 1.11.1 for.
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