{"record":{"id":"0d2fdaf53ed6c05f","repo":"crowdsecurity/crowdsec","slug":"while-closing-s-server-w","errorCode":null,"errorMessage":"while closing %s server: %w","messagePattern":"while closing (.+?) server: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/acquisition/modules/http/run.go","lineNumber":296,"sourceCode":"\t\t\t}\n\t\t} else {\n\t\t\ts.logger.Infof(\"start http server on %s\", s.Config.ListenAddr)\n\n\t\t\terr := s.Server.ListenAndServe()\n\t\t\tif err != nil && err != http.ErrServerClosed {\n\t\t\t\treturn fmt.Errorf(\"http server failed: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t})\n\n\t<-t.Dying()\n\n\ts.logger.Infof(\"%s datasource stopping\", s.GetName())\n\n\tif err := s.Server.Close(); err != nil {\n\t\treturn fmt.Errorf(\"while closing %s server: %w\", s.GetName(), err)\n\t}\n\n\treturn nil\n}\n\nfunc (s *Source) StreamingAcquisition(ctx context.Context, out chan pipeline.Event, t *tomb.Tomb) error {\n\ts.logger.Debugf(\"start http server on %s\", s.Config.ListenAddr)\n\n\tt.Go(func() error {\n\t\tdefer trace.ReportPanic()\n\t\treturn s.RunServer(ctx, out, t)\n\t})\n\n\treturn nil\n}\n","sourceCodeStart":278,"sourceCodeEnd":312,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/http/run.go#L278-L312","documentation":"On shutdown (t.Dying() fires), RunServer calls http.Server.Close(); if the forced close reports an error it is wrapped with the datasource name. This is rare — Close usually succeeds even with active connections, which it terminates.","triggerScenarios":"Datasource is stopping and s.Server.Close() returns non-nil, e.g. internal server state corruption or the underlying listener already broken/closed by an earlier failure.","commonSituations":"Shutdown racing a previous serve failure that already tore down the listener; custom instrumentation/Upgrade handlers returning errors through Close; process teardown under heavy load.","solutions":["Check earlier logs for a preceding serve error that explains the broken server state; fix the root cause.","Retry the shutdown/restart of crowdsec; the error is usually benign on teardown.","Report upstream with logs if it recurs on every clean shutdown.","Ensure no external actor is forcibly closing the listening socket during operation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := srv.Close(); err != nil { log.Warnf(\"server close: %v\", err) // treat as non-fatal on teardown }","preventionTips":["Log-and-tolerate close errors during shutdown.","Fix any earlier serve failures that leave the server broken.","Test graceful shutdown in staging."],"tags":["http","shutdown","server"],"backgroundTag":"http-request-failed","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"}