From 49ce9a4b07da6ae0da25e19a34e91b4664d8b2a5 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 30 Jun 2022 00:10:44 -0400 Subject: [PATCH] 16552: Fix signal handling. Signal handlers shouldn't stop when Start returns. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- lib/boot/supervisor.go | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) 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() } }() -- 2.30.2