[NOD-1018] Exit after 2 minutes if graceful shutdown fails (#732)

* [NOD-1018] Exit after 2 minutes if graceful shutdown fails

* [NOD-1018] Change time.Tick to time.After
This commit is contained in:
Ori Newman 2020-05-25 14:30:43 +03:00 committed by GitHub
parent 6463a4b5d0
commit 6219b93430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ import (
"runtime/debug"
"runtime/pprof"
"strings"
"time"
"github.com/kaspanet/kaspad/dbaccess"
@ -145,7 +146,20 @@ func kaspadMain(serverChan chan<- *server.Server) error {
defer func() {
kasdLog.Infof("Gracefully shutting down the server...")
server.Stop()
server.WaitForShutdown()
shutdownDone := make(chan struct{})
go func() {
server.WaitForShutdown()
shutdownDone <- struct{}{}
}()
const shutdownTimeout = 2 * time.Minute
select {
case <-shutdownDone:
case <-time.After(shutdownTimeout):
kasdLog.Criticalf("Graceful shutdown timed out %s. Terminating...", shutdownTimeout)
}
srvrLog.Infof("Server shutdown complete")
}()
server.Start()