Skip to content

feat: make the backend dial timeout configurable (--backend-dial-timeout)#570

Merged
itzg merged 1 commit into
itzg:mainfrom
CODECRAFTCLOUD:feat/configurable-backend-dial-timeout
Jul 13, 2026
Merged

feat: make the backend dial timeout configurable (--backend-dial-timeout)#570
itzg merged 1 commit into
itzg:mainfrom
CODECRAFTCLOUD:feat/configurable-backend-dial-timeout

Conversation

@wachirachoomsiri

Copy link
Copy Markdown
Contributor

Follow-up to #569, which bounded the backend dial with a fixed 2s timeout so the auto-scale asleep MOTD is served promptly instead of hanging on the OS SYN-retry for a scaled-to-zero backend. This makes that bound configurable via a new --backend-dial-timeout flag (env BACKEND_DIAL_TIMEOUT), keeping the existing 2s as the default — so behavior is unchanged unless the flag is set.

Why

The ideal value depends on how quickly backends are reachable:

  • On Kubernetes / in-cluster Services a healthy backend accepts the TCP connection in sub-millisecond time, so operators can lower the timeout (e.g. 100ms) to serve the asleep MOTD and trigger scale-up almost instantly on a scaled-to-zero Service.
  • Deployments with slower or higher-latency backends can keep 2s (or raise it) to avoid treating a reachable-but-slow backend as asleep.

A single hard-coded constant can't serve both. #569 deliberately chose a conservative 2s; this leaves that as the default while letting operators tune it. (We run mc-router at 100ms on a Kubernetes Minecraft-hosting deployment where every backend is an on-cluster Service.)

Changes

  • server/configs.go — add BackendDialTimeout time.Duration (default:"2s") to Config.
  • server/connector.go — replace the backendDialTimeout constant with a per-Connector field (default defaultBackendDialTimeout = 2s) plus a UseBackendDialTimeout() setter, matching the existing UseAsleepMOTD / UseClientFilter style; the dial in findAndConnectBackend reads the field.
  • server/server.go — wire config.BackendDialTimeout into the connector.
  • README.md — document the new flag in the Usage list.

Testing

  • go vet ./... and go test ./server/... ./mcproto/... pass.
  • With no flag set, the dial uses the same 2s bound as before (defaultBackendDialTimeout).
  • --help lists -backend-dial-timeout duration … (default 2s).

…out)

Follow-up to itzg#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>
wachirachoomsiri added a commit to CODECRAFTCLOUD/mc-router that referenced this pull request Jul 12, 2026
Dial-timeout (itzg#569) is now upstream, so this reconciles history. uniz keeps
its configurable --backend-dial-timeout (PR itzg#570 pending) and wake-ux patches;
no file changes result (uniz already contains all upstream content).
@itzg
itzg merged commit 7df261c into itzg:main Jul 13, 2026
1 of 2 checks passed
wachirachoomsiri added a commit to CODECRAFTCLOUD/mc-router that referenced this pull request Jul 13, 2026
@itzg

itzg commented Jul 19, 2026

Copy link
Copy Markdown
Owner

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.

2 participants