fix(shutdown): fix crash when shutting down before server and task scheduler have started. (#2148)

init shutdown routine after controller.Init()
check for nil values before stopping http server and task scheduler.

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
peusebiu
2024-01-06 03:50:48 +02:00
committed by GitHub
parent 59f41ac17d
commit a46e10269a
3 changed files with 10 additions and 7 deletions
-4
View File
@@ -41,8 +41,6 @@ func signalHandler(ctlr *api.Controller, sigCh chan os.Signal) {
// gracefully shutdown http server
ctlr.Shutdown() //nolint: contextcheck
close(sigCh)
}
}
@@ -61,8 +59,6 @@ func initShutDownRoutine(ctlr *api.Controller) {
func (hr *HotReloader) Start() {
done := make(chan bool)
initShutDownRoutine(hr.ctlr)
// run watcher
go func() {
defer hr.watcher.Close()
+2
View File
@@ -69,6 +69,8 @@ func newServeCmd(conf *config.Config) *cobra.Command {
return err
}
initShutDownRoutine(ctlr)
if err := ctlr.Run(); err != nil {
log.Error().Err(err).Msg("failed to start controller, exiting")
}