From 5d015904323657552db0c6da9cb7a72daf994da0 Mon Sep 17 00:00:00 2001 From: lysu Date: Mon, 25 May 2020 10:38:28 +0800 Subject: [PATCH] tikv: fix panic after sending fail with ambiguous errors (#17211) --- store/tikv/client_batch.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/store/tikv/client_batch.go b/store/tikv/client_batch.go index 08520afc51219..efa5237c8511c 100644 --- a/store/tikv/client_batch.go +++ b/store/tikv/client_batch.go @@ -232,6 +232,7 @@ func (c *batchCommandsClient) send(request *tikvpb.BatchCommandsRequest, entries logutil.BgLogger().Info( "sending batch commands meets error", zap.String("target", c.target), + zap.Uint64s("requestIDs", request.RequestIds), zap.Error(err), ) c.failPendingRequests(err) @@ -345,10 +346,10 @@ func (c *batchCommandsClient) batchRecvLoop(cfg config.TiKVClient, tikvTransport for i, requestID := range resp.GetRequestIds() { value, ok := c.batched.Load(requestID) if !ok { - // There shouldn't be any unknown responses because if the old entries - // are cleaned by `failPendingRequests`, the stream must be re-created - // so that old responses will be never received. - panic("batchRecvLoop receives a unknown response") + // this maybe caused by batchCommandsClient#send meets ambiguous error that request has be sent to TiKV but still report a error. + // then TiKV will send response back though stream and reach here. + logutil.BgLogger().Warn("batchRecvLoop receives outdated response", zap.Uint64("requestID", requestID)) + continue } entry := value.(*batchCommandsEntry) logutil.Eventf(entry.ctx, "receive %T response with other %d batched requests from %s", responses[i].GetCmd(), len(responses), c.target)