Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interrupt corner case - addInterruptHandler hangs #154

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions signal.go
Expand Up @@ -9,6 +9,8 @@ import (
"os/signal"
)

var shutdownInProgress bool

// interruptChannel is used to receive SIGINT (Ctrl+C) signals.
var interruptChannel chan os.Signal

Expand All @@ -27,7 +29,9 @@ func mainInterruptHandler() {
for {
select {
case <-interruptChannel:
shutdownInProgress = true
btcdLog.Infof("Received SIGINT (Ctrl+C). Shutting down...")

// run handlers in LIFO order.
for i := range interruptCallbacks {
idx := len(interruptCallbacks) - 1 - i
Expand All @@ -47,6 +51,12 @@ func mainInterruptHandler() {
// addInterruptHandler adds a handler to call when a SIGINT (Ctrl+C) is
// received.
func addInterruptHandler(handler func()) {
// if shutdown is in progress, just finish the handler and exit
if shutdownInProgress {
handler()
return
}

// Create the channel and start the main interrupt handler which invokes
// all other callbacks and exits if not already done.
if interruptChannel == nil {
Expand Down