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

Cancel node context after StopAll #8289

Merged
merged 8 commits into from Jan 25, 2021
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
6 changes: 5 additions & 1 deletion beacon-chain/node/node.go
Expand Up @@ -60,6 +60,7 @@ const testSkipPowFlag = "test-skip-pow"
type BeaconNode struct {
cliCtx *cli.Context
ctx context.Context
cancel context.CancelFunc
services *shared.ServiceRegistry
lock sync.RWMutex
stop chan struct{} // Channel to wait for termination notifications.
Expand Down Expand Up @@ -153,9 +154,11 @@ func NewBeaconNode(cliCtx *cli.Context) (*BeaconNode, error) {

registry := shared.NewServiceRegistry()

ctx, cancel := context.WithCancel(cliCtx.Context)
beacon := &BeaconNode{
cliCtx: cliCtx,
ctx: cliCtx.Context,
ctx: ctx,
cancel: cancel,
services: registry,
stop: make(chan struct{}),
stateFeed: new(event.Feed),
Expand Down Expand Up @@ -278,6 +281,7 @@ func (b *BeaconNode) Close() {
if err := b.db.Close(); err != nil {
log.Errorf("Failed to close database: %v", err)
}
b.cancel()
close(b.stop)
}

Expand Down
2 changes: 1 addition & 1 deletion slasher/node/node.go
Expand Up @@ -150,11 +150,11 @@ func (n *SlasherNode) Close() {
defer n.lock.Unlock()

log.Info("Stopping hash slinging slasher")
n.cancel()
n.services.StopAll()
if err := n.db.Close(); err != nil {
log.Errorf("Failed to close database: %v", err)
}
n.cancel()
close(n.stop)
}

Expand Down
6 changes: 6 additions & 0 deletions validator/node/node.go
Expand Up @@ -45,6 +45,8 @@ import (
// the entire lifecycle of services attached to it participating in eth2.
type ValidatorClient struct {
cliCtx *cli.Context
ctx context.Context
cancel context.CancelFunc
db *kv.Store
services *shared.ServiceRegistry // Lifecycle and service store.
lock sync.RWMutex
Expand Down Expand Up @@ -76,8 +78,11 @@ func NewValidatorClient(cliCtx *cli.Context) (*ValidatorClient, error) {
prereq.WarnIfNotSupported(cliCtx.Context)

registry := shared.NewServiceRegistry()
ctx, cancel := context.WithCancel(cliCtx.Context)
ValidatorClient := &ValidatorClient{
cliCtx: cliCtx,
ctx: ctx,
cancel: cancel,
services: registry,
walletInitialized: new(event.Feed),
stop: make(chan struct{}),
Expand Down Expand Up @@ -154,6 +159,7 @@ func (c *ValidatorClient) Close() {

c.services.StopAll()
log.Info("Stopping Prysm validator")
c.cancel()
close(c.stop)
}

Expand Down