-
Notifications
You must be signed in to change notification settings - Fork 110
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
fix(grpc): stop server on SIGTERM and SIGINT #647
Conversation
Signed-off-by: dionysius <[email protected]>
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.
LGTM
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.
You could use https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/manager/signals/signal.go#L29, this is what we use for the operator controllers:
@niladrih I've considered it, but it will crash since https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/manager/signals/signal.go#L24. This function is only allowed to be called once. Thats why the notes that the function should be called somewhere on the "top" of the application and the This PR is designed to be small and concise. Any better approach is a bigger refactor. |
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.
Makes sense. Could you add a // TODO:
comment explaining the tech debt involved in this approach? Thanks.
Hmm... I was about to prepare such commit. I just saw one more option, define:
on package level for |
Yeah, this variant doesn't look to bad either: https://github.com/openebs/zfs-localpv/compare/develop...dionysius:zfs-localpv:grpc_stop_2?expand=1. But needs some comments and a quick check here since I want to be sure that two routines can wait for the channel simultanously |
No, it doesn't behave the same. While the issue might be fixed (the process stops), it doesn't report the stopped routines (there are a few missing):
Yeah this PR is the quick way to go, anything else would be best using a context and or "proxy"copy the I've updated the places with TODO infos accordingly. |
Signed-off-by: dionysius <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## develop #647 +/- ##
===========================================
- Coverage 95.99% 95.91% -0.08%
===========================================
Files 1 1
Lines 574 686 +112
===========================================
+ Hits 551 658 +107
- Misses 19 23 +4
- Partials 4 5 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@dionysius Are we good to merge? |
Why is this PR required? What issue does it fix?: Stopping the binary doesn't exit the process because the grpc server goroutine is still running and doesn't get cancelled in any form.
What this PR does?: Listens (additionally, see below) to system signals SIGTERM and SIGINT to handle grpc server stopping.
Does this PR require any upgrade changes?: no
If the changes in this PR are manually verified, list down the scenarios covered:: Stopping the binary in agent mode will now stop the process (since all goroutines have naturally stopped).
Any additional information for your reviewer? :
This is only a quick solution but small and concise. Better approach would be a refactoring and passing around of the stop-channel from the top. Even better would be to introduce a clean context instead for the whole lifetime of the application process. Even the used function which register those signals has been updated to return a context many years ago: https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/manager/signals/signal.go. See also: https://stackoverflow.com/a/74895157 and https://gist.github.com/embano1/e0bf49d24f1cdd07cffad93097c04f0a
Checklist:
<type>(<scope>): <subject>