Compare commits

..

1 Commits

Author SHA1 Message Date
Ori Newman
6219b93430 [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
2020-05-25 14:30:43 +03:00

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()