fix: bound backend dial with a timeout so asleep MOTD is served promptly#569
Merged
Merged
Conversation
Dialing a Service whose StatefulSet is scaled to 0 hangs on the OS SYN-retry timeout (~30s) because the ClusterIP has no endpoints. The auto-scale asleep MOTD is only served from the dial-failure fallback, so the client's server-list ping times out before the MOTD arrives (MOTD "shows only sometimes"). Bound the dial with net.DialTimeout. A healthy backend accepts the TCP connection almost instantly, so this only trips on unreachable/asleep backends, letting the existing status fallback serve the asleep MOTD promptly. Verified on a live cluster: asleep MOTD went from ~30s (usually a client timeout) to ~2s. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
wachirachoomsiri
added a commit
to CODECRAFTCLOUD/mc-router
that referenced
this pull request
Jul 12, 2026
itzg
pushed a commit
that referenced
this pull request
Jul 13, 2026
…out) (#570) Follow-up to #569: replace the fixed 2s backendDialTimeout constant with a --backend-dial-timeout flag (env BACKEND_DIAL_TIMEOUT), defaulting to the same 2s. Operators whose backends are reachable quickly (e.g. on-cluster Kubernetes Services) can lower it so the asleep MOTD / scale-up fallback fires sooner on a scaled-to-zero backend. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Owner
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.
Problem
With
--auto-scale-up, when a backend's StatefulSet is scaled to 0 its ClusterIP Service has no endpoints.net.Dial("tcp", backendHostPort)on that address hangs on the OS SYN-retry timeout (~30s) instead of failing fast.The auto-scale asleep MOTD is only served from the dial-failure fallback in
findAndConnectBackend. Because the dial hangs ~30s, a client's server-list ping usually gives up before the fallback runs — so the asleep MOTD "shows only sometimes".Fix
Bound the backend dial with
net.DialTimeout(2s). A healthy backend accepts the TCP connection almost instantly, so this only trips on unreachable/asleep backends — letting the existing status fallback serve the asleep MOTD promptly.Evidence
Verified on a live Kubernetes cluster: asleep MOTD went from ~30s (usually a client timeout, MOTD never shown) to ~2s.
Note
The 2s bound is a const (
backendDialTimeout) — happy to make it a flag if you'd prefer that over a fixed value.🤖 Generated with Claude Code