Skip to content

dnsforward: build new server state before stopping the old one - #8589

Open
ChenYun10 wants to merge 1 commit into
AdguardTeam:masterfrom
ChenYun10:fix/reconfigure-downtime
Open

dnsforward: build new server state before stopping the old one#8589
ChenYun10 wants to merge 1 commit into
AdguardTeam:masterfrom
ChenYun10:fix/reconfigure-downtime

Conversation

@ChenYun10

@ChenYun10 ChenYun10 commented Sep 3, 2026

Copy link
Copy Markdown

Problem

Server.Reconfigure currently stops the running proxy first, then does a blind time.Sleep(100 * time.Millisecond), and only then prepares the new state (loading upstreams, bootstrapping, building the filtering proxy). During this whole window the listeners are down and clients get "connection refused" on every settings change.

Fix

Build the new state before tearing the old one down, and remove the 100 ms sleep. The old proxy, bootstrap resolvers and address processor are shut down explicitly after the new state is prepared, shrinking the actual downtime to just the final swap and start.

Notes

  • The exclusive serverLock is still held for the whole operation (it serializes request handling). A full fix would build the new proxy outside the lock and only swap under a brief critical section; that is left as a follow-up since Prepare currently mutates many fields of s.
  • Verified: go build ./... and go test ./internal/dnsforward/ pass; smoke-tested by triggering POST /control/dns_config and observing the reconfiguration complete in ~2 ms with DNS resolution continuing afterwards.

Signed-off-by: Chen Yun <zouminchen09@gmail .com>

Reconfigure previously stopped the running proxy first, then slept for
100 ms, and only then prepared the new state.  This kept the listeners
down for the whole (potentially slow) preparation — including upstream
loading and bootstrap resolution — and made clients get "connection
refused" during every settings change.

Build the new state before tearing the old one down, and remove the blind
100 ms sleep.  The old proxy and its resources are shut down explicitly
after the new state is prepared, shrinking the actual downtime window to
just the final swap and start.

Signed-off-by: Chen Yun <ChenYun10@users.noreply.github.com>
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.

1 participant