Skip to content

v3rpc: map lease.ErrNotPrimary to codes.Unavailable instead of codes.Unknown#21856

Open
crawfordxx wants to merge 1 commit into
etcd-io:mainfrom
crawfordxx:fix-lease-not-primary-grpc-code
Open

v3rpc: map lease.ErrNotPrimary to codes.Unavailable instead of codes.Unknown#21856
crawfordxx wants to merge 1 commit into
etcd-io:mainfrom
crawfordxx:fix-lease-not-primary-grpc-code

Conversation

@crawfordxx
Copy link
Copy Markdown

Which issue(s) does the PR fix:

Fixes #21671

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

[BUG] v3rpc: lease keepalive now returns codes.Unavailable (not codes.Unknown) when the server is not the primary lessor, allowing clients to retry on another member.

Summary

lease.ErrNotPrimary was missing from toGRPCErrorMap in
server/etcdserver/api/v3rpc/util.go. When LeaseRenew returned this
error (e.g. after a leader switch causes ensureLeadership() to fail),
togRPCError fell through to the catch-all status.Error(codes.Unknown, …),
surfacing as gRPC code 2 (Unknown) with the message
"not a primary lessor" — giving clients no signal that retrying on a
different member would succeed.

Root cause

togRPCError uses a direct map lookup (toGRPCErrorMap[err]), so every
sentinel error that should map to a specific gRPC code must be listed
explicitly. lease.ErrNotPrimary was never added.

Fix

  1. api/v3rpc/rpctypes/error.go — add ErrGRPCNotPrimary = codes.Unavailable
    alongside the other lease errors, register it in errStringToError and the
    client-side ErrNotPrimary var.
  2. server/etcdserver/api/v3rpc/util.go — map lease.ErrNotPrimary → rpctypes.ErrGRPCNotPrimary.

codes.Unavailable is consistent with ErrGRPCNoLeader and
ErrGRPCLeaderChanged and is the correct code for "this member can't serve
the request right now, try another one".

…Unknown

When LeaseRenew returns lease.ErrNotPrimary, togRPCError falls through to
status.Error(codes.Unknown, ...) because ErrNotPrimary is absent from the
toGRPCErrorMap. This surfaces to clients as gRPC code 2 (Unknown) with
message "not a primary lessor", which gives no indication that a retry on
a different member is appropriate.

Add ErrGRPCNotPrimary = codes.Unavailable alongside the other lease errors,
register it in errStringToError and the client-side error vars, and map
lease.ErrNotPrimary to it in toGRPCErrorMap. Unavailable is consistent with
ErrGRPCNoLeader and ErrGRPCLeaderChanged and signals to clients that the
current member is temporarily unavailable for this operation.

Fixes etcd-io#21671

Signed-off-by: crawfordxx <crawfordxx@users.noreply.github.com>
@k8s-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: crawfordxx
Once this PR has been reviewed and has the lgtm label, please assign jmhbnz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Copy Markdown

Hi @crawfordxx. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Unexpected Unknown grpc code for ErrNotPrimary

2 participants