{"record":{"id":"207a3da186bd90f7","repo":"AdguardTeam/AdGuardHome","slug":"shutting-down-dnssvc-w","errorCode":null,"errorMessage":"shutting down dnssvc: %w","messagePattern":"shutting down dnssvc: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/next/cmd/service.go","lineNumber":116,"sourceCode":"\n\ts.logger.DebugContext(ctx, \"wrote pid\", \"file\", s.pidFilePath, \"pid\", pid)\n}\n\n// Shutdown implements the [service.Interface] interface for *serviceMgr.\nfunc (s *serviceMgr) Shutdown(ctx context.Context) (err error) {\n\ts.confMgrMu.RLock()\n\tdefer s.confMgrMu.RUnlock()\n\n\tvar errs []error\n\n\terr = s.confMgr.Web().Shutdown(ctx)\n\tif err != nil {\n\t\terrs = append(errs, fmt.Errorf(\"shutting down web: %w\", err))\n\t}\n\n\terr = s.confMgr.DNS().Shutdown(ctx)\n\tif err != nil {\n\t\terrs = append(errs, fmt.Errorf(\"shutting down dnssvc: %w\", err))\n\t}\n\n\ts.removePID(ctx)\n\n\treturn errors.Join(errs...)\n}\n\n// removePID removes the PID file.  Any errors are reported to log.\nfunc (s *serviceMgr) removePID(ctx context.Context) {\n\tif s.pidFilePath == \"\" {\n\t\treturn\n\t}\n\n\terr := os.Remove(s.pidFilePath)\n\tif err != nil {\n\t\ts.logger.ErrorContext(ctx, \"removing pidfile\", slogutil.KeyError, err)\n\n\t\treturn","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/next/cmd/service.go#L98-L134","documentation":"Graceful shutdown of the DNS server failed; joined with the web shutdown error via errors.Join and reported after removePID.","triggerScenarios":"confMgr.DNS().Shutdown(ctx) errors: context deadline exceeded while draining queries, socket close errors, or UDP goroutines stuck.","commonSituations":"Refresh under heavy DNS load where in-flight queries exceed the shutdown window; rare fd/socket errors on shutdown during container teardown.","solutions":["Widen the shutdown deadline for the Refresh/Shutdown context","Reduce load or wait for query drain before reconfiguring","Check logs for stuck handlers if persistent"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := s.Shutdown(ctx); err != nil {\n\tlog.Warnf(\"shutdown issues (may be drain timeouts): %v\", err)\n\tif !procExited() { /* escalate: force kill */ }\n}","preventionTips":["Drain DNS traffic before reconfiguration windows","Monitor for stuck handlers via metrics/logging"],"tags":["dns","shutdown","timeout"],"backgroundTag":"graceful-shutdown-timeout","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}