-
Notifications
You must be signed in to change notification settings - Fork 387
fix: speed up node shutdown #5408
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7bed9a2
fix: speed up node shutdown
sbackend123 4deb8ab
fix: remove close.Once after discussion
sbackend123 bae9b0e
fix: closing api
sbackend123 30e6c3c
fix: add time span
sbackend123 2482a69
Merge branch 'master' into fix/shutdown-node
sbackend123 94a2665
Merge branch 'master' into fix/shutdown-node
sbackend123 d2eeb63
fix: make linter happy
sbackend123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ import ( | |
| const LoggerName = "node" | ||
|
|
||
| type Bee struct { | ||
| logger log.Logger | ||
| p2pService io.Closer | ||
| p2pHalter p2p.Halter | ||
| ctxCancel context.CancelFunc | ||
|
|
@@ -260,6 +261,7 @@ func NewBee( | |
| }) | ||
|
|
||
| b = &Bee{ | ||
| logger: logger, | ||
| ctxCancel: ctxCancel, | ||
| errorLogWriter: sink, | ||
| tracerCloser: tracerCloser, | ||
|
|
@@ -1350,12 +1352,15 @@ func (b *Bee) Shutdown() error { | |
| } | ||
| // tryClose is a convenient closure which decrease | ||
| // repetitive io.Closer tryClose procedure. | ||
| tryClose := func(c io.Closer, errMsg string) { | ||
| tryClose := func(c io.Closer, component string) { | ||
| if c == nil { | ||
| return | ||
| } | ||
|
|
||
| b.logger.Debug("starting shutdown", "component", component) | ||
| defer b.logger.Debug("finished shutdown", "component", component) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it is worth to add to it the time-span it took to shut down the component |
||
| if err := c.Close(); err != nil { | ||
| mErr = multierror.Append(mErr, fmt.Errorf("%s: %w", errMsg, err)) | ||
| mErr = multierror.Append(mErr, fmt.Errorf("%s: %w", component, err)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1429,9 +1434,10 @@ func (b *Bee) Shutdown() error { | |
| tryClose(b.tracerCloser, "tracer") | ||
| tryClose(b.topologyCloser, "topology driver") | ||
| tryClose(b.storageIncetivesCloser, "storage incentives agent") | ||
| // close localstore before StateStore to avoid ErrClosed / incomplete flush. | ||
| tryClose(b.localstoreCloser, "localstore") | ||
| tryClose(b.stateStoreCloser, "statestore") | ||
| tryClose(b.stamperStoreCloser, "stamperstore") | ||
| tryClose(b.localstoreCloser, "localstore") | ||
| tryClose(b.resolverCloser, "resolver service") | ||
|
|
||
| return mErr | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,9 @@ type reacher struct { | |
| peerHeap peerHeap // min-heap ordered by retryAfter | ||
| peerIndex map[string]*peer // lookup by overlay for O(1) access | ||
|
|
||
| newPeer chan struct{} | ||
| quit chan struct{} | ||
| newPeer chan struct{} | ||
| quit chan struct{} | ||
| closeOnce sync.Once | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
|
||
| pinger p2p.Pinger | ||
| notifier p2p.ReachableNotifier | ||
|
|
@@ -290,15 +291,11 @@ func (r *reacher) jitter(d time.Duration) time.Duration { | |
| return time.Duration(float64(d) * j) | ||
| } | ||
|
|
||
| // Close stops the worker. Must be called once. | ||
| // Close stops the worker. | ||
| func (r *reacher) Close() error { | ||
| select { | ||
| case <-r.quit: | ||
| return nil | ||
| default: | ||
| } | ||
|
|
||
| close(r.quit) | ||
| r.closeOnce.Do(func() { | ||
| close(r.quit) | ||
| }) | ||
| r.wg.Wait() | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed? how come that a quit signal can happen twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this is the protection of the double closed channel, which is panicing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that is clear. the question is why would the channel be closed twice in the first place? it suggests a problem in the calling code no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that it is just a common protection, as there is no way to restrict how many times an exported method is called. I did not notice that the Close method is called twice anywhere, but I suppose that a layer of safety is a good thing here.