From f0553e57ba5b0afa3999dab212c231f69764d6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poyraz=20K=C3=BC=C3=A7=C3=BCkarslan?= <83272398+PoyrazK@users.noreply.github.com> Date: Thu, 7 May 2026 18:34:03 +0300 Subject: [PATCH] fix: add s.done check before refreshZone in handleNotify goroutine The handleNotify async goroutine only checked s.done once at startup, then proceeded to long-running operations (Repo.GetZone, refreshZone) without further shutdown checks. Add a second check before refreshZone to allow early exit during server shutdown, avoiding unnecessary work. Fixes #82. --- internal/dns/server/server.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/dns/server/server.go b/internal/dns/server/server.go index 327c790..2e463f7 100644 --- a/internal/dns/server/server.go +++ b/internal/dns/server/server.go @@ -1314,6 +1314,7 @@ func (s *Server) handleNotify(ctx context.Context, request *packet.DNSPacket, cl // Trigger async refresh if it's a slave zone if !s.DisableAsync { go func(zoneName string) { + // Check for cancellation or shutdown before starting long-running operations. select { case <-ctx.Done(): return @@ -1327,6 +1328,14 @@ func (s *Server) handleNotify(ctx context.Context, request *packet.DNSPacket, cl return } if zone != nil && zone.Role == "slave" { + // Check again before refresh to avoid unnecessary work during shutdown. + select { + case <-ctx.Done(): + return + case <-s.done: + return + default: + } s.refreshZone(ctx, zone) } }(request.Questions[0].Name)