Repository navigation
Conversation
…ckoff When a tunnel connection ends after it had registered and stayed up for at least tunnelRetryDuration, start it again at once instead of queueing it behind the supervisor's shared reconnect backoff. Until the connection registers again, the edge keeps routing requests to it and answers them with a 502, so the shared backoff's random 0-20 s (0-10 s with --retries 0) turns into failed requests even though the connection had been healthy. A connection that fails before registering, or that lasted less than tunnelRetryDuration, still waits for the shared backoff, so a connection reconnects at once at most once per tunnelRetryDuration, as region changes do. EdgeTunnelServer.Serve keeps its per-connection backoff, which spreads reconnects after an event that closes many connections. startFirstTunnel now reads its protocol fallback once, before connection 0 can register: it read the map again on every retry while initialize adds the other connections' entries. Fixes cloudflare#1782
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
tunnelRetryDuration, the supervisor now starts it again at once. It no longer queues the connection behind the shared reconnect backoff (supervisor/supervisor.go).connection with edge closedis the common case.tunnelRetryDuration, still wait for the shared backoff. So a connection reconnects at once at most once pertunnelRetryDuration, the same limit region changes use.startFirstTunnelreads itsprotocolFallbackonce, before connection 0 can register. It used to reads.tunnelsProtocolFallbackagain on every retry, whileinitializeadds the other connections' entries to that map once connection 0 has registered. The new test's connection-0 case trips the race detector on the old code.EdgeTunnelServer.Servestill waits its own per-connection backoff before it returns (0–2 s with the default--retries, 0–1 s with--retries 0). Reconnects after an event that closes many connections at once stay spread out.Why
--retries 0), even for a connection that served for hours. Its second-close window can double that. The backoff is right for a connection that cannot be established. It is not needed for one that the edge closed after serving.--retries 0(30 days, 160 single-connection closes): close-to-registration gap mean 6.5 s, median 6 s, p90 11 s. Requests routed into those gaps failed with 502.Tests
TestReconnectAfterServedConnectionCloses(testing/synctest) covers four cases. A connection that served for an hour reconnects at the same instant it closed, for connection 0 (startFirstTunnel) and for the others. One that closed one second after registering, or that never registered, waits for the shared backoff.go test -race ./supervisor/ ./retry/passes;gofmtandgo vetclean;golangci-lint run ./supervisor/...reports 0 issues.End to end, against the real edge, with a connector using 4 HA connections over HTTP/2: each trial dropped our outbound packets of one connection's flow and then closed its socket. That reproduces an edge-side close the edge itself does not see. 12 trials per build at 20 requests/s:
Registered tunnel connectionEvery failure was a 502 that started after the close and ended about 20 s later. What remains after the change is the per-connection jitter, the dial and registration, and the edge's own switch-over.
Fixes #1782
🤖 Generated with Claude Code