From 40c25958b272d7dbb16c941c25f4e126f7dc9f07 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Mon, 1 Jun 2020 14:52:20 +0200 Subject: [PATCH] go/oasis-node: Make sure the node only tries to stop once This could previously result in a panic during shutdown. --- .changelog/2964.bugfix.md | 3 +++ go/oasis-node/cmd/node/node.go | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 .changelog/2964.bugfix.md diff --git a/.changelog/2964.bugfix.md b/.changelog/2964.bugfix.md new file mode 100644 index 00000000000..c6935df2e9d --- /dev/null +++ b/.changelog/2964.bugfix.md @@ -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. diff --git a/go/oasis-node/cmd/node/node.go b/go/oasis-node/cmd/node/node.go index de18f1c51aa..9af8ab09c91 100644 --- a/go/oasis-node/cmd/node/node.go +++ b/go/oasis-node/cmd/node/node.go @@ -7,7 +7,7 @@ import ( "fmt" "os" "path/filepath" - "sync/atomic" + "sync" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -100,7 +100,7 @@ type Node struct { svcTmnt tmService.TendermintService svcTmntSeed *tendermint.SeedService - stopping uint32 + stopOnce sync.Once commonStore *persistent.CommonStore @@ -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