Skip to content

Commit

Permalink
Add timeouts for graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
csstaub committed Apr 12, 2016
1 parent 7b5d12e commit 75a5025
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"os/signal"
"syscall"
"time"
)

// signalHandler for server mode. Listens for incoming SIGTERM or SIGUSR1
Expand All @@ -45,6 +46,10 @@ func serverSignalHandler(listener net.Listener, statusListener net.Listener, sto
switch sig {
case syscall.SIGTERM:
logger.Printf("received SIGTERM, stopping listener")
time.AfterFunc(5*time.Minute, func() {
logger.Printf("graceful shutdown timeout: exiting")
exitFunc(1)
})
return

case syscall.SIGUSR1:
Expand Down Expand Up @@ -90,6 +95,10 @@ func clientSignalHandler(listener net.Listener, reloadClient chan bool, stopper
switch sig {
case syscall.SIGTERM:
logger.Printf("received SIGTERM, stopping listener")
time.AfterFunc(5*time.Minute, func() {
logger.Printf("graceful shutdown timeout: exiting")
exitFunc(1)
})
signal.Stop(signals)
stopper <- true
listener.Close()
Expand Down

0 comments on commit 75a5025

Please sign in to comment.