From 5630f9ef8ccda4b633697e6b4e948432bee28107 Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Fri, 26 May 2023 20:57:08 -0700 Subject: [PATCH] Fix hangs on SIGTERM. This fixes #1469, where three bugs pervent main from existing on SIGTERM. The first two are blocking receiving from cancel chanels which never have values sent to them, cancelStateUpdateChan and cancelPolicyUpdateChan. It seems closing the chanels should be all the is needed to signal the watching goroutines to exit. The other is the signal hander never exiting an infinite for loop. The sigFunc is called in an errorGroup which blocks exiting Serve and thus main. It looks like a refactor in #1382 removed an os.Exit(0), replacing it with a return breaks out of the loop. --- hscontrol/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hscontrol/app.go b/hscontrol/app.go index c654d4a647..2ddd6ad7f9 100644 --- a/hscontrol/app.go +++ b/hscontrol/app.go @@ -760,7 +760,6 @@ func (h *Headscale) Serve() error { // Stop listening (and unlink the socket if unix type): socketListener.Close() - <-h.cancelStateUpdateChan close(h.stateUpdateChan) close(h.cancelStateUpdateChan) @@ -775,6 +774,7 @@ func (h *Headscale) Serve() error { // And we're done: cancel() + return } } }