commit 2a9126a1581a9e2bf5c8fbcd6992cfe57d8df831 Author: David Fifield david@bamsoftware.com Date: Wed Jan 18 19:24:02 2017 -0800
Simplify signal handling in WebSocket server.
pt-spec no longer talks about SIGINT. --- server/server.go | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/server/server.go b/server/server.go index b5417b5..570de61 100644 --- a/server/server.go +++ b/server/server.go @@ -320,9 +320,9 @@ func main() { var numHandlers int = 0 var sig os.Signal sigChan := make(chan os.Signal, 1) - signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(sigChan, syscall.SIGTERM)
- // wait for first signal + // keep track of handlers and wait for a signal sig = nil for sig == nil { select { @@ -331,27 +331,16 @@ func main() { case sig = <-sigChan: } } - log.Printf("Got first signal %q with %d running handlers.", sig, numHandlers) + + // signal received, shut down + log.Printf("Caught signal %q, exiting.", sig) for _, ln := range listeners { ln.Close() } - - if sig == syscall.SIGTERM { - log.Printf("Caught signal %q, exiting.", sig) - return - } - - // wait for second signal or no more handlers - sig = nil - for sig == nil && numHandlers != 0 { - select { - case n := <-handlerChan: - numHandlers += n - log.Printf("%d remaining handlers.", numHandlers) - case sig = <-sigChan: + for n := range handlerChan { + numHandlers += n + if numHandlers == 0 { + break } } - if sig != nil { - log.Printf("Got second signal %q with %d running handlers.", sig, numHandlers) - } }
tor-commits@lists.torproject.org