mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 20:38:08 +08:00
fix(scheduler): fix data race (#2085)
* fix(scheduler): data race when pushing new tasks the problem here is that scheduler can be closed in two ways: - canceling the context given as argument to scheduler.RunScheduler() - running scheduler.Shutdown() because of this shutdown can trigger a data race between calling scheduler.inShutdown() and actually pushing tasks into the pool workers solved that by keeping a quit channel and listening on both quit channel and ctx.Done() and closing the worker chan and scheduler afterwards. Signed-off-by: Petu Eusebiu <peusebiu@cisco.com> * refactor(scheduler): refactor into a single shutdown before this we could stop scheduler either by closing the context provided to RunScheduler(ctx) or by running Shutdown(). simplify things by getting rid of the external context in RunScheduler(). keep an internal context in the scheduler itself and pass it down to all tasks. Signed-off-by: Petu Eusebiu <peusebiu@cisco.com> --------- Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
@@ -61,20 +61,16 @@ func newServeCmd(conf *config.Config) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
/* context used to cancel go routines so that
|
||||
we can change their config on the fly (restart routines with different config) */
|
||||
reloaderCtx := hotReloader.Start()
|
||||
hotReloader.Start()
|
||||
|
||||
if err := ctlr.Init(reloaderCtx); err != nil {
|
||||
if err := ctlr.Init(); err != nil {
|
||||
ctlr.Log.Error().Err(err).Msg("failed to init controller")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ctlr.Run(reloaderCtx); err != nil {
|
||||
if err := ctlr.Run(); err != nil {
|
||||
log.Error().Err(err).Msg("failed to start controller, exiting")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user