{"record":{"id":"002337e222bf59fb","repo":"crowdsecurity/crowdsec","slug":"while-waiting-on-httpservertomb-w","errorCode":null,"errorMessage":"while waiting on httpServerTomb: %w","messagePattern":"while waiting on httpServerTomb: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/apiserver/apiserver.go","lineNumber":501,"sourceCode":"\tif s.httpServer != nil {\n\t\tif err := s.httpServer.Shutdown(ctx); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// close io.writer logger given to gin\n\tif pipe, ok := gin.DefaultErrorWriter.(*io.PipeWriter); ok {\n\t\tpipe.Close()\n\t}\n\n\tif pipe, ok := gin.DefaultWriter.(*io.PipeWriter); ok {\n\t\tpipe.Close()\n\t}\n\n\ts.httpServerTomb.Kill(nil)\n\n\tif err := s.httpServerTomb.Wait(); err != nil {\n\t\treturn fmt.Errorf(\"while waiting on httpServerTomb: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (s *APIServer) AttachPluginBroker(broker *csplugin.PluginBroker) {\n\ts.controller.PluginChannel = broker.PluginChannel\n}\n\nfunc hasPlugins(profiles []*csconfig.ProfileCfg) bool {\n\tfor _, profile := range profiles {\n\t\tif len(profile.Notifications) != 0 {\n\t\t\treturn true\n\t\t}\n\t}\n\n\treturn false\n}","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/apiserver.go#L483-L519","documentation":"APIServer.Shutdown wraps an error returned by httpServerTomb.Wait() — the serving goroutine reported an error while being killed during shutdown. Normally Wait returns nil on graceful kill; a non-nil value means the server died abnormally.","triggerScenarios":"Shutdown called (process stopping, SIGTERM/SIGINT) and listenAndServeLAPI had already failed or returned an error during the kill sequence.","commonSituations":"Shutdown after a listener failure; tomb race where the goroutine errored concurrently with shutdown; bugs in plugin/connection close paths earlier in Shutdown.","solutions":["Log the wrapped cause; it usually mirrors the listen failure (604) or http.Server.Serve error.","If the process is exiting anyway, this is often benign — the original cause matters more.","Ensure only one Shutdown/Run lifecycle per APIServer instance.","Check for nil/failed listeners earlier in the shutdown sequence (e.g. pipe.Close errors)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := apiServer.Shutdown(); err != nil {\n    log.Warnf(\"LAPI shutdown reported: %v\", err) // usually benign at exit\n}","preventionTips":["Always call Run before Shutdown; never shut down twice.","Log the wrapped cause to catch real listener failures early.","Graceful-signal handling: SIGTERM -> Shutdown once.","Treat non-nil Wait errors as symptoms of earlier failures, not root causes."],"tags":["shutdown","lifecycle","lapi"],"backgroundTag":"invalid-state-transition","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}