-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(run): Add sigterm handler sample #1902
Conversation
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
d4143c4
to
df2a722
Compare
The testing is not complete, but can you review if this addresses your comments? @ahmetb |
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.
Left some more comments.
I need guidance on passing the "Build and lint" test. I ran |
instead of creating a merge commit, maybe try |
run/sigterm-handler/main.go
Outdated
defer func() { | ||
// Add extra handling here to close any DB connections, redis, or flush logs | ||
cancel() // Release resources | ||
}() |
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 can shorten this by doing defer cancel()
but this is also ok if Adam’s ok with 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.
Normally I'd be for shortening this, but one of our main goals for the sample is to help developers know how to do these cleanup steps, so the extra flag for "drop code here" seems helpful.
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'd expect that cleanup code to happen outside this defer, ideally using the same ctx
?
I might be missing something.
Please make sure to test it locally (I'm guessing by adding some time.Sleep in the handler function) and see if it behaves nicely. |
Works locally. Updating Kokoro to run e2e tests on presubmit #2005 |
run/sigterm-handler/main.go
Outdated
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
|
||
defer func() { | ||
// Add extra handling here to close any DB connections, redis, or flush logs. |
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.
Not sure where the comment went. But, I'd expect any DB connections, etc. to handled outside this defer
call. I might be missing something.
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.
@grayside please advise
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'm not sure the idiomatic approach here, did a little searching to see how folks talk about this, and in the first 5 results, 2 of them do cleanup inside the defer and three just do them after the shutdown.
This was just asked at https://stackoverflow.com/a/66860299/54929. |
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.
One logging comment, otherwise looks good.
go1.16 tests are successful. |
Admins please merge. |
No description provided.