-
Notifications
You must be signed in to change notification settings - Fork 372
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
Don't store contexts in lease pool structs #4733
Conversation
This revealed and depends on #4744. |
This pull request has merge conflicts that need to be resolved. |
The context shouldn't be stored in structs, but passed as the first argument to functions and methods. Remove the context storage from the lease pool and pass it to the methods where it's actually needed. Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
if err != nil { | ||
return err | ||
} | ||
events, cancel, err := leasePool.Watch() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) |
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 don't understand this change.
Why shouldn't the context.WithCancel
be based on the one Start
gets as an argument? If that context is Done I think this should be done too.
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 is one of the big issues that exists with the component model in k0s. See #4357 and its predecessor #1844.
So from my point of view, the context passed to Start
should be used to cancel any async/blocking operations that are performed during startup. Any asynchronous operations that happen as a result of the component being started should be handled by Stop
.
if err != nil { | ||
return err | ||
} | ||
events, cancel, err := leasePool.Watch() | ||
ctx, cancel := context.WithCancel(context.Background()) |
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.
Same thing here.
Description
The context shouldn't be stored in structs, but passed as the first argument to functions and methods. Remove the context storage from the lease pool and pass it to the methods where it's actually needed.
See:
Type of change
How Has This Been Tested?
Checklist: