From 2a554c43b09af6030b77a9a25dcf5ee3ed9c06af Mon Sep 17 00:00:00 2001 From: "Owain G. Ainsworth" Date: Tue, 10 Dec 2013 18:21:34 +0000 Subject: [PATCH] Shutdown server fully on ctrl-c since we don't wait for peers, this largely just waits for the server procs themselves to die. Unless the entire server is wedged (which is what kill -9 is for) this should always shut down fairly swiftly. This should mean we sync addrmanager and disestablish upnp correctly on interrupt. Discussed with davec. --- btcd.go | 6 ++++++ server.go | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/btcd.go b/btcd.go index 4aad4b510..c0a186f96 100644 --- a/btcd.go +++ b/btcd.go @@ -94,6 +94,11 @@ func btcdMain(serverChan chan<- *server) error { cfg.Listeners, err) return err } + addInterruptHandler(func() { + btcdLog.Infof("Gracefully shutting down the server...") + server.Stop() + server.WaitForShutdown() + }) server.Start() if serverChan != nil { serverChan <- server @@ -107,6 +112,7 @@ func btcdMain(serverChan chan<- *server) error { // for the interrupt handler goroutine to finish. go func() { server.WaitForShutdown() + srvrLog.Infof("Server shutdown complete") shutdownChannel <- true }() diff --git a/server.go b/server.go index 639a005af..524d8601e 100644 --- a/server.go +++ b/server.go @@ -728,7 +728,6 @@ func (s *server) Stop() error { // WaitForShutdown blocks until the main listener and peer handlers are stopped. func (s *server) WaitForShutdown() { s.wg.Wait() - srvrLog.Infof("Server shutdown complete") } // ScheduleShutdown schedules a server shutdown after the specified duration.