Skip to content

Commit

Permalink
Fix hangs on SIGTERM.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
armooo committed May 27, 2023
1 parent feb1536 commit 1eeceab
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions hscontrol/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,9 @@ func (h *Headscale) Serve() error {
// Stop listening (and unlink the socket if unix type):
socketListener.Close()

<-h.cancelStateUpdateChan
close(h.stateUpdateChan)
close(h.cancelStateUpdateChan)

<-h.cancelPolicyUpdateChan
close(h.policyUpdateChan)
close(h.cancelPolicyUpdateChan)

Expand All @@ -765,6 +763,7 @@ func (h *Headscale) Serve() error {

// And we're done:
cancel()
return
}
}
}
Expand Down

0 comments on commit 1eeceab

Please sign in to comment.