Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/oasis-node: Make sure the node only tries to stop once #2964

Merged
merged 1 commit into from Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .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.
11 changes: 5 additions & 6 deletions go/oasis-node/cmd/node/node.go
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