-
Notifications
You must be signed in to change notification settings - Fork 10.3k
lease: Fix incorrect gRPC Unavailable on client cancel during LeaseKeepAlive forwarding #21122
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,6 @@ import ( | |||||||||||||||||||||||||||||||||||||||
| "go.uber.org/zap" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| pb "go.etcd.io/etcd/api/v3/etcdserverpb" | ||||||||||||||||||||||||||||||||||||||||
| "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" | ||||||||||||||||||||||||||||||||||||||||
| "go.etcd.io/etcd/server/v3/etcdserver" | ||||||||||||||||||||||||||||||||||||||||
| "go.etcd.io/etcd/server/v3/lease" | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -98,11 +97,12 @@ func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err | |||||||||||||||||||||||||||||||||||||||
| select { | ||||||||||||||||||||||||||||||||||||||||
| case err = <-errc: | ||||||||||||||||||||||||||||||||||||||||
| case <-stream.Context().Done(): | ||||||||||||||||||||||||||||||||||||||||
| // the only server-side cancellation is noleader for now. | ||||||||||||||||||||||||||||||||||||||||
| // We end up here due to: | ||||||||||||||||||||||||||||||||||||||||
| // 1. Client cancellation | ||||||||||||||||||||||||||||||||||||||||
| // 2. Server cancellation: the client ctx is wrapped with WithRequireLeader, | ||||||||||||||||||||||||||||||||||||||||
| // monitorLeader() detects no leader and thus cancels this stream with ErrGRPCNoLeader. | ||||||||||||||||||||||||||||||||||||||||
| // 3. Server cancellation: the server is shutting down. | ||||||||||||||||||||||||||||||||||||||||
| err = stream.Context().Err() | ||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks good. We don’t need to adjust that error handling. If the issue is caused by monitorLeader, RenewLeader will be canceled and will return no-leader to the client as well. At least we don’t log canceled events for the no-leader case. etcd/server/etcdserver/v3_server.go Lines 543 to 561 in 6d5e199
(Line 554) |
||||||||||||||||||||||||||||||||||||||||
| if errors.Is(err, context.Canceled) { | ||||||||||||||||||||||||||||||||||||||||
| err = rpctypes.ErrGRPCNoLeader | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -401,13 +401,23 @@ func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, e | |||
| } | ||||
| } | ||||
| // Throttle in case of e.g. connection problems. | ||||
| time.Sleep(50 * time.Millisecond) | ||||
| select { | ||||
| case <-time.After(50 * time.Millisecond): | ||||
| case <-cctx.Done(): | ||||
| } | ||||
| } | ||||
|
|
||||
| if errorspkg.Is(cctx.Err(), context.DeadlineExceeded) { | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding line 404, could we just keep it as it is right now? I don’t think it’s related to this fix.
|
||||
| err := cctx.Err() | ||||
| switch { | ||||
| case errorspkg.Is(err, context.DeadlineExceeded): | ||||
| return -1, errors.ErrTimeout | ||||
| case errorspkg.Is(err, context.Canceled): | ||||
| return -1, errors.ErrCanceled | ||||
| // Should be unreachable, but we keep it defensive. | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The log "Unexpected lease renew ..." already conveys this comment.
Suggested change
|
||||
| default: | ||||
| s.Logger().Warn("Unexpected lease renew context error", zap.Error(err)) | ||||
|
Comment on lines
+411
to
+418
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the exact issue you are fixing? If there is no a real issue, suggest not to change this. It might have impact on client side. |
||||
| return -1, errors.ErrTimeout | ||||
| } | ||||
| return -1, errors.ErrCanceled | ||||
| } | ||||
|
|
||||
| func (s *EtcdServer) checkLeaseTimeToLive(ctx context.Context, leaseID lease.LeaseID) (uint64, error) { | ||||
|
|
||||
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 a useful comment. Most other are not.
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.
Will keep raising my standard for comments going forward!