mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
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:
parent
59f41ac17d
commit
a46e10269a
3 changed files with 10 additions and 7 deletions
|
@ -370,13 +370,18 @@ func (c *Controller) LoadNewConfig(newConfig *config.Config) {
|
||||||
|
|
||||||
func (c *Controller) Shutdown() {
|
func (c *Controller) Shutdown() {
|
||||||
c.StopBackgroundTasks()
|
c.StopBackgroundTasks()
|
||||||
|
|
||||||
|
if c.Server != nil {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_ = c.Server.Shutdown(ctx)
|
_ = c.Server.Shutdown(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will stop scheduler and wait for all tasks to finish their work.
|
// Will stop scheduler and wait for all tasks to finish their work.
|
||||||
func (c *Controller) StopBackgroundTasks() {
|
func (c *Controller) StopBackgroundTasks() {
|
||||||
|
if c.taskScheduler != nil {
|
||||||
c.taskScheduler.Shutdown()
|
c.taskScheduler.Shutdown()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) StartBackgroundTasks() {
|
func (c *Controller) StartBackgroundTasks() {
|
||||||
|
|
|
@ -41,8 +41,6 @@ func signalHandler(ctlr *api.Controller, sigCh chan os.Signal) {
|
||||||
|
|
||||||
// gracefully shutdown http server
|
// gracefully shutdown http server
|
||||||
ctlr.Shutdown() //nolint: contextcheck
|
ctlr.Shutdown() //nolint: contextcheck
|
||||||
|
|
||||||
close(sigCh)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +59,6 @@ func initShutDownRoutine(ctlr *api.Controller) {
|
||||||
func (hr *HotReloader) Start() {
|
func (hr *HotReloader) Start() {
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
|
||||||
initShutDownRoutine(hr.ctlr)
|
|
||||||
|
|
||||||
// run watcher
|
// run watcher
|
||||||
go func() {
|
go func() {
|
||||||
defer hr.watcher.Close()
|
defer hr.watcher.Close()
|
||||||
|
|
|
@ -69,6 +69,8 @@ func newServeCmd(conf *config.Config) *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initShutDownRoutine(ctlr)
|
||||||
|
|
||||||
if err := ctlr.Run(); err != nil {
|
if err := ctlr.Run(); err != nil {
|
||||||
log.Error().Err(err).Msg("failed to start controller, exiting")
|
log.Error().Err(err).Msg("failed to start controller, exiting")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue