From 98c9288bc268c220c8dc0cedbfd014d34b47d7be Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Wed, 16 Sep 2020 13:42:38 +0800 Subject: [PATCH] cherry pick #20030 to release-4.0 Signed-off-by: ti-srebot --- store/tikv/region_request.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/store/tikv/region_request.go b/store/tikv/region_request.go index 68ec62b9cd91e..52783aad679c9 100644 --- a/store/tikv/region_request.go +++ b/store/tikv/region_request.go @@ -400,6 +400,13 @@ func (s *RegionRequestSender) sendReqToRegion(bo *Backoffer, rpcCtx *RPCContext, } resp, err = s.client.SendRequest(ctx, rpcCtx.Addr, req, timeout) if err != nil { + // Because in rpc logic, context.Cancel() will be transferred to rpcContext.Cancel error. For rpcContext cancel, + // we need to retry the request. But for context cancel active, for example, limitExec gets the required rows, + // we shouldn't retry the request, it will go to backoff and hang in retry logic. + if ctx.Err() != nil && errors.Cause(ctx.Err()) == context.Canceled { + return nil, false, errors.Trace(ctx.Err()) + } + s.rpcError = err if e := s.onSendFail(bo, rpcCtx, err); e != nil { return nil, false, errors.Trace(e)