-
Notifications
You must be signed in to change notification settings - Fork 752
Small cleanup in App
and Node
#3962
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
base: master
Are you sure you want to change the base?
Conversation
d1bffe0
to
b8d9b39
Compare
It seems to me that the |
While that's true, we should note that all exit codes that are of endogenous reasons are 1, and all of exogenous reasons are 0, so in practice - it is highly unlikely that this can have a race. |
@yacovm A second invocation of |
Oh you're right! My bad :-) |
|
||
// Stop notifies the application to exit and returns immediately. | ||
// Stop should only be called after [Start]. | ||
// It is safe to call Stop multiple times. | ||
Stop() error | ||
Stop() | ||
|
||
// ExitCode should only be called after [Start] returns with no error. It |
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.
This comment should be updated
@@ -129,9 +128,7 @@ func Run(app App) int { | |||
close(stackTraceSignal) | |||
|
|||
// if there was an error closing or running the application, report that error |
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.
Comment should be updated
@@ -148,7 +145,7 @@ type app struct { | |||
// Start the business logic of the node (as opposed to config reading, etc). | |||
// Does not block until the node is done. Errors returned from this method |
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.
Comment is stale
} | ||
|
||
// Stop attempts to shutdown the currently running node. This function will | ||
// return immediately. | ||
func (a *app) Stop() error { | ||
// block until shutdown is complete. |
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.
This comment change isn't really inaccurate (at least based on the intention of the original code).
Calling Shutdown(0)
on the node doesn't actually block until shutdown finishes. Shutdown
finishes when Dispatch()
returns. Notice that Shutdown
only starts the shutdown process.
|
||
// If the P2P server isn't running, shut down the node. | ||
// If node is already shutting down, this does nothing. | ||
// If node is already shutting down, this does not tigger shutdown again, | ||
// and blocks until the shutdown is complete. |
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.
// and blocks until the shutdown is complete. | |
// and blocks until the shutdown returns. |
@@ -682,7 +676,8 @@ func (n *Node) Dispatch() error { | |||
) | |||
} | |||
// If the API server isn't running, shut down the node. | |||
// If node is already shutting down, this does nothing. | |||
// If node is already shutting down, this does not tigger shutdown again, | |||
// and blocks until the shutdown is complete. |
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.
// and blocks until the shutdown is complete. | |
// and blocks until the shutdown returns. |
Why this should be merged
While preparing a new RPC-signer PR, I noticed a few things that could be improved/simplified. There are 4 different atomic commits - feel free to take or leave any of them :)
How this works
shuttingDown
atomic flag which could lead toshuttingDownExitCode
being set more than once.App
-Start()
,Stop()
,ExitCode()
always returnnil
errors. I removed the error returns from the function signatures, which makes the possible code paths much easier to reason about.DoneShuttingDown
inNode
is redundant, because theOnce.Do()
insideShutdown()
will block until shutdown is completed.n.Net.Dispatch()
is used as the return value, but only ~25 lines later. Renamed toretErr
to make it more clear that it is the error that should be returned.How this was tested
Existing tests
Need to be documented in RELEASES.md?
No