refactor: move network monitoring to separate goroutine

- Move network monitoring initialization out of serveDNS() function
- Start network monitoring in a separate goroutine during program startup
- Remove context parameter from monitorNetworkChanges() as it's not used
- Simplify serveDNS() function signature by removing unused context parameter
- Ensure network monitoring starts only once during initial run, not on reload

This change improves separation of concerns by isolating network monitoring
from DNS serving logic, and prevents potential issues with multiple
monitoring goroutines if starting multiple listeners.
This commit is contained in:
Cuong Manh Le
2025-08-01 18:55:07 +07:00
committed by Cuong Manh Le
parent 38f0b84d44
commit ed147a3362
2 changed files with 6 additions and 6 deletions
+6
View File
@@ -514,6 +514,12 @@ func (p *prog) run(reload bool, reloadCh chan struct{}) {
for listenerNum := range p.cfg.Listener {
p.cfg.Listener[listenerNum].Init()
if !reload {
go func() {
// Start network monitoring
if err := p.monitorNetworkChanges(ctx); err != nil {
mainLog.Load().Error().Err(err).Msg("Failed to start network monitoring")
}
}()
go func(listenerNum string) {
listenerConfig := p.cfg.Listener[listenerNum]
upstreamConfig := p.cfg.Upstream[listenerNum]