Skip to content

Ingester client: release the gRPC connection when stream setup fails - #7969

Open
arpitjain099 wants to merge 1 commit into
cortexproject:masterfrom
arpitjain099:fix/ingester-client-leak-on-stream-setup-failure
Open

arpitjain099 wants to merge 1 commit into
cortexproject:masterfrom
arpitjain099:fix/ingester-client-leak-on-stream-setup-failure

Conversation

@arpitjain099

Copy link
Copy Markdown

What this PR does:

With -distributor.use-stream-push enabled, MakeIngesterClient opens the gRPC connection before it starts the push-stream workers. If starting them fails it returns the error without closing that connection or cancelling the stream context. ring/client.Pool only records a client after the factory succeeds, so nothing is left holding the connection and nothing can ever close it, and its reconnect loop keeps dialing the ingester address until the process exits. The failures cluster while an ingester's address is still in the ring but already unreachable, so each rollout leaks a burst of them, and a querier reaches the same factory from the read path.

The error path now cancels the stream context and closes the connection. Run also collected the workers' error in a plain variable written by all 100 of them, which go test -race reports, so it is now an atomic.Error as in pkg/ring/batch.go.

The new test drives MakeIngesterClient against an address that refuses connections and fails on master.

I used Claude Code while preparing this, and I have reviewed and tested the change myself.

Which issue(s) this PR fixes:
Fixes #7759

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

@arpitjain099
arpitjain099 requested a review from a team as a code owner November 25, 2026 11:06
MakeIngesterClient returned the error from Run without closing the connection
or cancelling the stream context, so a discarded client left a connection
reconnecting to the ingester address for the lifetime of the process. Nothing
could reach it, because ring/client.Pool only records a client once the factory
has succeeded.

Run also stored the workers' error in a plain variable written by all of them
concurrently, which the race detector reports.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099
arpitjain099 force-pushed the fix/ingester-client-leak-on-stream-setup-failure branch from a3072da to e3bef13 Compare November 25, 2026 11:08

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MakeIngesterClient leaks grpc.ClientConn and goroutines on failure

1 participant