fix(httpserver): guard OnStop against nil srv when OnStart was never called
If a component earlier in the launcher sequence fails during OnInit or OnStart,
the launcher calls OnStop on every already-registered component for cleanup.
httpserver.OnStop previously called s.srv.Shutdown(ctx) unconditionally; because
s.srv is only assigned inside OnStart, any shutdown triggered before OnStart ran
caused a nil pointer panic.
Add an early return in OnStop: `if s.srv == nil { return nil }`.
This commit is contained in:
@@ -107,8 +107,12 @@ func (s *httpServer) OnStart() error {
|
||||
}
|
||||
|
||||
// OnStop performs a graceful shutdown, waiting up to 10 seconds for in-flight
|
||||
// requests to complete.
|
||||
// requests to complete. If OnStart was never called (e.g. a prior component
|
||||
// failed during startup), this is a no-op.
|
||||
func (s *httpServer) OnStop() error {
|
||||
if s.srv == nil {
|
||||
return nil
|
||||
}
|
||||
s.logger.Info("httpserver: shutting down gracefully")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user