-
Notifications
You must be signed in to change notification settings - Fork 178
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
[LifecycleManager] Adding shutdown signal #1077
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1077 +/- ##
==========================================
- Coverage 53.34% 53.34% -0.01%
==========================================
Files 318 318
Lines 21556 21559 +3
==========================================
Hits 11500 11500
- Misses 8484 8487 +3
Partials 1572 1572
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Discussed that offline, but I wonder if this simple approach isn't just a detour on the way towards threading a context. See https://github.com/dapperlabs/flow-go/issues/5720
@@ -57,6 +57,7 @@ type LifecycleManager struct { | |||
stopped chan struct{} // used to signal that shutdown has completed | |||
startupCommenced bool // indicates whether OnStart() has been invoked | |||
shutdownCommenced bool // indicates whether OnStop() has been invoked | |||
shutdownSignal chan struct{} // used to signal that shutdown has commenced |
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.
isn't this already conveyed by shutdownCommenced
?
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.
Yes, but shutdownCommenced
is not something which the user of the lifecycle manager has access to. This feature enables someone to "subscribe" to the shutdown commenced event (by reading from the channel), so goroutines launched by the user of the lifecycle can use this to know when they are signalled to shutdown
@huitseeker Thanks for bringing this up, after some more thought I actually tend to agree. However, I realized that actually a lot more work needs to be done to refactor our codebase to be able to use contexts properly, at the root of which lies splitting the capability to check the state of a component ( I think Leo actually had a good point here about each component having a single owner. What I realize now is that we actually want to model a Go program as a call-graph where each goroutine has a single parent:
If we have this, then contexts provide a very composable, elegant solution for managing branches of our call-graph:
In this way, successive layers of the call-graph can create a Context that adheres to their needs without affecting their parents. By splitting into two interfaces, we can ensure that only a single goroutine will have access to a component's |
This PR updates
LifecycleManager
to have a shutdown signal which can be used by the component using it to know when shutdown has commenced.