Skip to content

[probes.grpc] Drop cached connection on DeadlineExceeded/Unavailable - #1501

Merged
manugarg merged 3 commits into
mainfrom
grpc-drop-conn-on-error
Sep 24, 2026
Merged

manugarg merged 3 commits into
mainfrom
grpc-drop-conn-on-error

Conversation

@manugarg

@manugarg manugarg commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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_conn works 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 DeadlineExceeded or Unavailable, so the next probe run reconnects (and re-resolves). Other errors, like a NOT_SERVING health check or a validation failure, keep the connection. The check is skipped when disable_reuse_conn is set.

We considered adding HTTP/2 keepalive (grpc.WithKeepaliveParams) instead. It needs a new config knob, and default grpc-go servers reply with GOAWAY too_many_pings to 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.go now keeps the gRPC status in its errors: it wraps with %w, and the call-failure path wraps h.Status.Err() instead of only h.Status.Message(). Before this, status.Code() always returned Unknown for 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.Println that wrote the GENERIC request body to stdout when body_file was used.

Testing: new TestDropConnOnError covers 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 the generic_request.go change. go test -race ./probes/grpc/ passes.

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.
@manugarg
manugarg merged commit aa0617b into main Sep 24, 2026
13 checks passed
@manugarg
manugarg deleted the grpc-drop-conn-on-error branch September 24, 2026 22:05
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.

1 participant