Skip to content

Commit

Permalink
kvclient: switch error in ctx cancel edge case
Browse files Browse the repository at this point in the history
This patch changes the error returned by the DistSender on a cancelled
ctx. Depending on the exactly who detects the ctx as cancelled, there
are a number of different possibilities - too many to enumerate here.
Generally, the client is supposed to get a context.Canceled error,
wrapped in different layers. The code path that this patch changes is
about the cancellation being detected by sendPartialBatch() without it
having been previously detected by sendToReplicas(). This path is
unusual (sendToReplicas() generally detects the ctx cancelled). It's
also hard to test.
Depending on the exact cancellation timing, it's possible though for
sendPartialBatch() to detect it instead. In this case, this patch makes
it so that, if sendToReplicas() returned a sendError (indicating that
a suitable replica could not be reached and that the higher layer is
expected to continue trying other replicas), the error returned to the
client is a cancellation error instead of the sendError.

Touches #69419

Release note: None
  • Loading branch information
andreimatei committed Sep 13, 2021
1 parent 386e099 commit 9ddcc52
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/kv/kvclient/kvcoord/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,9 +1558,6 @@ func (ds *DistSender) sendPartialBatch(
}

if err != nil {
// Set pErr so that, if we don't perform any more retries, the
// deduceRetryEarlyExitError() call below the loop is inhibited.
pErr = roachpb.NewError(err)
switch {
case errors.HasType(err, sendError{}):
// We've tried all the replicas without success. Either they're all
Expand All @@ -1582,6 +1579,9 @@ func (ds *DistSender) sendPartialBatch(
routingTok.Evict(ctx)
continue
}
// Set pErr so that the deduceRetryEarlyExitError() call below the loop is
// inhibited.
pErr = roachpb.NewError(err)
break
}

Expand Down

0 comments on commit 9ddcc52

Please sign in to comment.