fix: use background context for DNS listeners to survive reloads

Change DNS listener context from parent context to background context
so that listeners continue running during configuration reloads.
Listener configuration changes require a service restart, not reload,
so listeners must persist across reload operations.

This prevents DNS listeners from being terminated when the parent
context is cancelled during reload operations.
This commit is contained in:
Cuong Manh Le
2025-09-03 18:49:22 +07:00
committed by Cuong Manh Le
parent 5d87bd07ca
commit a084c87370

View File

@@ -532,7 +532,10 @@ func (p *prog) run(reload bool, reloadCh chan struct{}) {
}
addr := net.JoinHostPort(listenerConfig.IP, strconv.Itoa(listenerConfig.Port))
p.Info().Msgf("starting DNS server on listener.%s: %s", listenerNum, addr)
if err := p.serveDNS(ctx, listenerNum); err != nil {
// serveCtx uses Background() context so listeners survive between reloads.
// Changes to listeners config require a service restart, not just reload.
serveCtx := context.Background()
if err := p.serveDNS(serveCtx, listenerNum); err != nil {
p.Fatal().Err(err).Msgf("unable to start dns proxy on listener.%s", listenerNum)
}
p.Debug().Msgf("end of serveDNS listener.%s: %s", listenerNum, addr)