-
Notifications
You must be signed in to change notification settings - Fork 381
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
Gracefully exit the program when the lease expired #2655
Conversation
Listen "LeaseKeepAliveResponse" channel returned by keepalive in ETCD client. When automatic renewal interruption is detected, the caller will be informed through Context, and then the caller can cancel the global context to exit the progrd.
Sorry for the slow reply, I've been at work trying to understand this change. The pattern you're using here feels a bit opaque:
I've created a change that I think is equivalent with respect to propagating etcd cancellation, but does it as:
This change is on my fork at https://github.com/google/trillian/compare/master...mhutchinson:etcd_keepalive?expand=1. If you like this, then please do integrate this into the PR. If this change breaks something, then let me know! |
Sorry for my bad english. Thanks a lot for your suggestion, I decided to go with it. But you removed the |
/gcbrun |
|
||
// listenKeepAliveRsp listens to `keepAliveRspCh` channel, and calls the cancel function | ||
// to notify the lease expired. | ||
func listenKeepAliveRsp(ctx context.Context, keepAliveRspCh <-chan *clientv3.LeaseKeepAliveResponse, cancel func()) { |
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.
Do you think it'd be slightly easier to grok if this method blocked and the caller is responsible for doing go listenKeepAliveRsp(...)
?
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.
fixed
util/process.go
Outdated
@@ -42,3 +42,21 @@ func AwaitSignal(ctx context.Context, doneFn func()) { | |||
glog.Infof("AwaitSignal canceled: %v", ctx.Err()) | |||
} | |||
} | |||
|
|||
// AwaitContext waits for context done, then runs the given function. |
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 be tempted to keep this as an unexported function in the serverutil
package it's called from...
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.
fixed
/gcbrun |
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.
@mhutchinson for a 2nd pair of eyes
This PR can let
trillian
proactively Listen "LeaseKeepAliveResponse" channel returned byKeepAlive
in ETCD client. When automatic renewal interruption is detected, Exit the program by canceling the context.Fixes #2654,#2249
Checklist