Repository navigation
[probes.grpc] Drop cached connection on DeadlineExceeded/Unavailable - #1501
Merged
Merged
Conversation
If the backend goes away silently (no RST), gRPC keeps the cached connection READY and every probe times out until TCP gives up on retransmissions (~15 min). TCP keepalive doesn't help since there is unacked data in flight. Drop and close the cached connection on transport-level errors so that the next probe run reconnects. This is skipped for disable_reuse_conn, where connections are closed after every run anyway.
GENERIC request errors were built with %v, or from just the status message, so status.Code() on them always returned Unknown. As a result, GENERIC probes never dropped the cached connection on DeadlineExceeded or Unavailable. Wrap errors with %w and wrap h.Status.Err() for the call failure path.
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.
If a backend goes away silently (no RST), gRPC keeps the cached connection READY. Every probe then times out until TCP gives up on retransmissions (~15 min with the default
tcp_retries2). TCP keepalive doesn't help here because there is unacked data in flight.disable_reuse_connworks around it, but it pays for a new connection on every probe.This change drops and closes the cached connection when the RPC fails with
DeadlineExceededorUnavailable, so the next probe run reconnects (and re-resolves). Other errors, like aNOT_SERVINGhealth check or a validation failure, keep the connection. The check is skipped whendisable_reuse_connis set.We considered adding HTTP/2 keepalive (
grpc.WithKeepaliveParams) instead. It needs a new config knob, and default grpc-go servers reply with GOAWAYtoo_many_pingsto client pings sent more often than every 5 minutes, which would cause spurious failures.Behavior change: a backend that is up but consistently slower than the probe timeout now costs one reconnect per failed probe.
For this to work with GENERIC probes,
generic_request.gonow keeps the gRPC status in its errors: it wraps with%w, and the call-failure path wrapsh.Status.Err()instead of onlyh.Status.Message(). Before this,status.Code()always returnedUnknownfor GENERIC errors. Side effect: GENERIC call-failure messages now include the code, e.g.gRPC call failed: rpc error: code = DeadlineExceeded desc = ....A separate commit removes a leftover
fmt.Printlnthat wrote the GENERIC request body to stdout whenbody_filewas used.Testing: new
TestDropConnOnErrorcovers ECHO and GENERIC. It checks that a successful run reuses the connection (1 connection after 2 runs) and a timed-out run drops it (2 connections after 2 runs). The test fails without the fix, and the GENERIC case fails without thegeneric_request.gochange.go test -race ./probes/grpc/passes.