Skip to content

Commit

Permalink
go/oasis-node: Make sure the node only tries to stop once
Browse files Browse the repository at this point in the history
This could previously result in a panic during shutdown.
  • Loading branch information
kostko committed Jun 1, 2020
1 parent 2761bf8 commit 40c2595
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/2964.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go/oasis-node: Make sure the node only tries to stop once

This could previously result in a panic during shutdown.
11 changes: 5 additions & 6 deletions go/oasis-node/cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"sync/atomic"
"sync"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -100,7 +100,7 @@ type Node struct {
svcTmnt tmService.TendermintService
svcTmntSeed *tendermint.SeedService

stopping uint32
stopOnce sync.Once

commonStore *persistent.CommonStore

Expand Down Expand Up @@ -143,10 +143,9 @@ func (n *Node) Cleanup() {

// Stop gracefully terminates the node.
func (n *Node) Stop() {
if !atomic.CompareAndSwapUint32(&n.stopping, 0, 1) {
return
}
n.svcMgr.Stop()
n.stopOnce.Do(func() {
n.svcMgr.Stop()
})
}

// Wait waits for the node to gracefully terminate. Callers MUST
Expand Down

0 comments on commit 40c2595

Please sign in to comment.