Skip to content

Commit 51201d3

Browse files
author
Leo Chen
authored
Merge pull request #2294 from rlan35/s3
Make graceful shutdown more robust and faster
2 parents ac4b6fc + d3dfd12 commit 51201d3

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

cmd/harmony/main.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,24 @@ func main() {
583583

584584
nodeConfig := createGlobalConfig()
585585
currentNode := setupConsensusAndNode(nodeConfig)
586+
587+
// Prepare for graceful shutdown from os signals
588+
osSignal := make(chan os.Signal)
589+
signal.Notify(osSignal, os.Interrupt, syscall.SIGTERM)
590+
go func() {
591+
for {
592+
select {
593+
case sig := <-osSignal:
594+
if sig == syscall.SIGTERM || sig == os.Interrupt {
595+
msg := "Got %s signal. Gracefully shutting down...\n"
596+
utils.Logger().Printf(msg, sig)
597+
fmt.Printf(msg, sig)
598+
currentNode.ShutDown()
599+
}
600+
}
601+
}
602+
}()
603+
586604
//setup state syncing and beacon syncing frequency
587605
currentNode.SetSyncFreq(*syncFreq)
588606
currentNode.SetBeaconSyncFreq(*beaconSyncFreq)
@@ -654,25 +672,6 @@ func main() {
654672
if currentNode.NodeConfig.GetMetricsFlag() {
655673
go currentNode.CollectMetrics()
656674
}
657-
// Prepare for graceful shutdown from os signals
658-
osSignal := make(chan os.Signal)
659-
signal.Notify(osSignal, os.Interrupt, os.Kill, syscall.SIGTERM)
660-
go func() {
661-
for {
662-
select {
663-
case sig := <-osSignal:
664-
if sig == os.Kill || sig == syscall.SIGTERM {
665-
fmt.Printf("Got %s signal. Gracefully shutting down...\n", sig)
666-
currentNode.ShutDown()
667-
}
668-
if sig == os.Interrupt {
669-
fmt.Printf("Got %s signal. Dumping state to DB...\n", sig)
670-
currentNode.Blockchain().Stop()
671-
currentNode.Beaconchain().Stop()
672-
}
673-
}
674-
}
675-
}()
676675

677676
currentNode.StartServer()
678677
}

node/node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ func (node *Node) SetBeaconSyncFreq(syncFreq int) {
689689
func (node *Node) ShutDown() {
690690
node.Blockchain().Stop()
691691
node.Beaconchain().Stop()
692-
node.StopServices()
693-
node.stopHTTP()
694-
fmt.Printf("Exiting node program...")
692+
msg := "Successfully shut down!\n"
693+
utils.Logger().Print(msg)
694+
fmt.Print(msg)
695695
os.Exit(0)
696696
}

0 commit comments

Comments
 (0)