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 2 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 (s *SlasherNode) Close() {
defer s.lock.Unlock()

log.Info("Stopping hash slinging slasher")
s.cancel()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same bug-prone code as in the beacon node - cancelling the parent context before StopAll is called.

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

Expand Down