diff --git a/pkg/kv/kvclient/kvcoord/dist_sender.go b/pkg/kv/kvclient/kvcoord/dist_sender.go index 68d78da05ea3..1fb1f8fe7bd9 100644 --- a/pkg/kv/kvclient/kvcoord/dist_sender.go +++ b/pkg/kv/kvclient/kvcoord/dist_sender.go @@ -2047,7 +2047,17 @@ func (ds *DistSender) sendPartialBatch( // and our local replica before attempting the request. If the sync // makes our token invalid, we handle it similarly to a RangeNotFound or // NotLeaseHolderError from a remote server. - if ba.ProxyRangeInfo != nil { + // NB: The routingTok is usually valid when we get to this line on a + // proxy request since we never retry the outer for loop, however there + // is an edge case where we invalidate the token once here and then + // invalidate it a second time in the statement below and hit a + // retriable range loopup error. + // TODO(baptist): Consider splitting out the handling in this method for + // proxy requests vs non-proxy requests. Currently it is hard to follow + // the invariants when this is called. Alternativly move this call to be + // done immediately when the routingTok is created as it will always be + // valid at that point. + if ba.ProxyRangeInfo != nil && routingTok.Valid() { routingTok.SyncTokenAndMaybeUpdateCache(ctx, &ba.ProxyRangeInfo.Lease, &ba.ProxyRangeInfo.Desc) } if !routingTok.Valid() {