Skip to content

Commit

Permalink
500 for grpc context canceled errors during login (#28866)
Browse files Browse the repository at this point in the history
  • Loading branch information
miagilepner authored Nov 8, 2024
1 parent 2c3c585 commit 09747c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 8 additions & 5 deletions vault/request_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -2121,11 +2121,14 @@ func isRetryableRPCError(ctx context.Context, err error) bool {
case codes.Unavailable:
return true
case codes.Canceled:
// if the request context is canceled, we want to return false
// but if the request context hasn't been canceled, then there was
// either an EOF or the RPC client context has been canceled which
// should be retried
return ctx.Err() == nil
// if the request context is canceled through a deadline exceeded, we
// want to return false. But otherwise, there could have been an EOF or
// the RPC client context has been canceled which should be retried
ctxErr := ctx.Err()
if ctxErr == nil {
return true
}
return !errors.Is(ctxErr, context.DeadlineExceeded)
case codes.Unknown:
// sometimes a missing HTTP content-type error can happen when multiple
// HTTP statuses have been written. This can happen when the error
Expand Down
11 changes: 10 additions & 1 deletion vault/request_handling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,25 @@ func TestRequestHandling_SecretLeaseMetric(t *testing.T) {
func TestRequestHandling_isRetryableRPCError(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()

deadlineCtx, deadlineCancel := context.WithDeadline(context.Background(), time.Now().Add(-1*time.Second))
defer deadlineCancel()
testCases := []struct {
name string
ctx context.Context
err error
want bool
}{
{
name: "req context canceled",
name: "req context canceled, not deadline",
ctx: ctx,
err: status.Error(codes.Canceled, "context canceled"),
want: true,
},
{
name: "req context deadline exceeded",
ctx: deadlineCtx,
err: status.Error(codes.Canceled, "context canceled"),
want: false,
},
{
Expand Down

0 comments on commit 09747c5

Please sign in to comment.