crowdsecurity/crowdsec · warning
while closing %s server: %w
Error message
while closing %s server: %w
What it means
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.
Source
Thrown at pkg/acquisition/modules/http/run.go:296
}
} else {
s.logger.Infof("start http server on %s", s.Config.ListenAddr)
err := s.Server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
return fmt.Errorf("http server failed: %w", err)
}
}
return nil
})
<-t.Dying()
s.logger.Infof("%s datasource stopping", s.GetName())
if err := s.Server.Close(); err != nil {
return fmt.Errorf("while closing %s server: %w", s.GetName(), err)
}
return nil
}
func (s *Source) StreamingAcquisition(ctx context.Context, out chan pipeline.Event, t *tomb.Tomb) error {
s.logger.Debugf("start http server on %s", s.Config.ListenAddr)
t.Go(func() error {
defer trace.ReportPanic()
return s.RunServer(ctx, out, t)
})
return nil
}
View on GitHub (pinned to 909b515798)
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.
Defensive patterns
Strategy: try-catch
Try / catch
if err := srv.Close(); err != nil { log.Warnf("server close: %v", err) // treat as non-fatal on teardown } Prevention
- Log-and-tolerate close errors during shutdown.
- Fix any earlier serve failures that leave the server broken.
- Test graceful shutdown in staging.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- https server failed: %w
- http server failed: %w
- path must start with /
- chunk_size must be positive
- invalid HTTP status code
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/0d2fdaf53ed6c05f.
Report an issue: GitHub.