Repository navigation
grpctunnel fixes (agent): reset reconnect backoff after a healthy stream; make forced re-registration single-flight - #173
Merged
Conversation
No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ation An established stream that ends should reset the reconnect backoff; forced re-registration should happen once per threshold crossing and only for streams that failed to open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d re-registration runOneStream now reports whether the stream was established. An established stream resets the reconnect backoff and does not count as an open failure. The forced re-registration claims the counter reset with a CompareAndSwap so workers failing together trigger it once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shawnburke
enabled auto-merge (squash)
October 24, 2026 03:25
keithfz
approved these changes
Oct 24, 2026
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.
Summary
Two bugs in
manageStream(agent/server/grpctunnel/tunnel_client.go):backoffwent back tominBackoffonly on the retired and Unauthenticated paths. A stream that served traffic for hours and then ended (GOAWAY max_age, EOF) kept the backoff of earlier, unrelated failures, so after a few routine drops every reconnect waited about 30s.runOneStreamnow also returnsestablished(the handshake completed), andmanageStreamresets tominBackoffwhen it is true. Repeated failures to open still back off exponentially.CompareAndSwap, so one threshold crossing forces one re-registration.consecFailuresgrew on any stream end. Only streams that failed to open now count, so a simultaneous drop of 5+ established slots no longer forces re-registration.Prod evidence
Slot 3
nextBackoffover 2026-10-22 to 2026-10-24, each failure hours apart with a successful "Tunnel stream re-established" in between: 1s -> 2s -> 4s -> 8s -> 16s.2026-10-23T18:49:11: "Repeated open failures; forcing re-registration" from 5 workers, followed by five "Registered with Cortex API" lines within 11ms.
TDD
Commits: (1)
jitteredbecomes a var so tests can skip the wait, no behavior change; (2) failing tests; (3) the fix.Tests drive
manageStreamworkers directly and reusefakeTunnelService,startFakeServer,newTestClientandwaitFor. The backoff test readsnextBackofffrom the existing "stream ended; will retry" log via zaptest/observer.Red (commit 2, before the fix)
Green (commit 3)
Also run:
go test -race ./server/grpctunnel/(ok, 3 runs), the new tests with-race -count=20(ok),go vet ./server/grpctunnel/(clean).🤖 Generated with Claude Code