From 9232aac873be161a98b8d434856bb09997f62c90 Mon Sep 17 00:00:00 2001 From: Ping Yu Date: Mon, 14 Aug 2023 17:27:35 +0800 Subject: [PATCH] executor: Fix coroutine leak after kill remote connection (#46035) close pingcap/tidb#46034 --- executor/simple.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/executor/simple.go b/executor/simple.go index a1895229fe5e9..13ad68e0a5bde 100644 --- a/executor/simple.go +++ b/executor/simple.go @@ -2608,6 +2608,7 @@ func killRemoteConn(ctx context.Context, sctx sessionctx.Context, gcid *globalco SetFromInfoSchema(sctx.GetInfoSchema()). SetStoreType(kv.TiDB). SetTiDBServerID(gcid.ServerID). + SetStartTS(math.MaxUint64). // To make check visibility success. Build() if err != nil { return err @@ -2618,6 +2619,14 @@ func killRemoteConn(ctx context.Context, sctx sessionctx.Context, gcid *globalco return err } + // Must consume & close the response, otherwise coprocessor task will leak. + defer func() { + _ = resp.Close() + }() + if _, err := resp.Next(ctx); err != nil { + return errors.Trace(err) + } + logutil.BgLogger().Info("Killed remote connection", zap.Uint64("serverID", gcid.ServerID), zap.Uint64("conn", gcid.ToConnID()), zap.Bool("query", query)) return err