From a7e4dfc305cf273a6083bef3d16d5a70608e79de Mon Sep 17 00:00:00 2001 From: Craig Peterson <192540+captncraig@users.noreply.github.com> Date: Mon, 21 Jan 2019 18:14:44 -0500 Subject: [PATCH 1/2] Run signal listener in a goroutine instead of deferring. Fixes #1679 --- cmd/helm-operator/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm-operator/main.go b/cmd/helm-operator/main.go index 64bf052ba..f4912c42a 100644 --- a/cmd/helm-operator/main.go +++ b/cmd/helm-operator/main.go @@ -131,7 +131,7 @@ func main() { errc <- fmt.Errorf("%s", <-c) }() - defer func() { + go func() { logger.Log("exiting...", <-errc) close(shutdown) shutdownWg.Wait() From 6bcfd3d27de49731c4c91364b1d6c6ef8e2925e8 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Wed, 13 Feb 2019 11:09:25 +0000 Subject: [PATCH 2/2] Move the shutdown wait to the end of helm-op main The general scheme in main.go is to start a bunch of goroutines, giving them a shutdown channel; then wait until there's a reason to exit, close the shutdown channel, and wait until the goroutines exit. This wasn't working, because the last stanza in main.go was _not_ run in a goroutine. This commit fixes that, and moves the graceful shutdown bit to the end, for clarity. --- cmd/helm-operator/main.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/helm-operator/main.go b/cmd/helm-operator/main.go index f4912c42a..8a1488417 100644 --- a/cmd/helm-operator/main.go +++ b/cmd/helm-operator/main.go @@ -131,12 +131,6 @@ func main() { errc <- fmt.Errorf("%s", <-c) }() - go func() { - logger.Log("exiting...", <-errc) - close(shutdown) - shutdownWg.Wait() - }() - mainLogger := log.With(logger, "component", "helm-operator") cfg, err := clientcmd.BuildConfigFromFlags(*master, *kubeconfig) @@ -195,9 +189,14 @@ func main() { go daemonhttp.ListenAndServe(*listenAddr, log.With(logger, "component", "daemonhttp"), shutdown) // start operator - if err = opr.Run(1, shutdown, shutdownWg); err != nil { - msg := fmt.Sprintf("Failure to run controller: %s", err.Error()) - logger.Log("error", msg) - errc <- fmt.Errorf(ErrOperatorFailure, err) - } + go func() { + if err = opr.Run(1, shutdown, shutdownWg); err != nil { + errc <- fmt.Errorf(ErrOperatorFailure, err) + } + }() + + shutdownErr := <-errc + logger.Log("exiting...", shutdownErr) + close(shutdown) + shutdownWg.Wait() }