From: Tom Clegg Date: Thu, 30 Jun 2022 04:10:44 +0000 (-0400) Subject: 16552: Fix signal handling. X-Git-Tag: 2.5.0~116^2~26 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/49ce9a4b07da6ae0da25e19a34e91b4664d8b2a5 16552: Fix signal handling. Signal handlers shouldn't stop when Start returns. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/lib/boot/supervisor.go b/lib/boot/supervisor.go index 52cd0b1616..9ed92cb1aa 100644 --- a/lib/boot/supervisor.go +++ b/lib/boot/supervisor.go @@ -113,28 +113,24 @@ func (super *Supervisor) Start(ctx context.Context) { super.done = make(chan struct{}) sigch := make(chan os.Signal) - signal.Notify(sigch, syscall.SIGINT, syscall.SIGTERM) - defer signal.Stop(sigch) + signal.Notify(sigch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) go func() { - for sig := range sigch { - super.logger.WithField("signal", sig).Info("caught signal") - if super.err == nil { - super.err = fmt.Errorf("caught signal %s", sig) - } - super.cancel() - } - }() - - hupch := make(chan os.Signal) - signal.Notify(hupch, syscall.SIGHUP) - defer signal.Stop(hupch) - go func() { - for sig := range hupch { - super.logger.WithField("signal", sig).Info("caught signal") - if super.err == nil { - super.err = errNeedConfigReload + defer signal.Stop(sigch) + for { + select { + case <-ctx.Done(): + return + case sig := <-sigch: + super.logger.WithField("signal", sig).Info("caught signal") + if super.err == nil { + if sig == syscall.SIGHUP { + super.err = errNeedConfigReload + } else { + super.err = fmt.Errorf("caught signal %s", sig) + } + } + super.cancel() } - super.cancel() } }()