Commit 2a9126a1 authored by David Fifield's avatar David Fifield
Browse files

Simplify signal handling in WebSocket server.

pt-spec no longer talks about SIGINT.
parent 57f72ab4
......@@ -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)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment