mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[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:
parent
6463a4b5d0
commit
6219b93430
16
kaspad.go
16
kaspad.go
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user