Skip to content

Commit

Permalink
executor: Fix coroutine leak after kill remote connection (#46035) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Aug 17, 2023
1 parent 79a02af commit b0f589e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,7 @@ func killRemoteConn(ctx context.Context, sctx sessionctx.Context, connID *util.G
SetFromInfoSchema(sctx.GetInfoSchema()).
SetStoreType(kv.TiDB).
SetTiDBServerID(connID.ServerID).
SetStartTS(math.MaxUint64). // To make check visibility success.
Build()
if err != nil {
return err
Expand All @@ -2639,6 +2640,14 @@ func killRemoteConn(ctx context.Context, sctx sessionctx.Context, connID *util.G
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", connID.ServerID),
zap.Uint64("conn", connID.ID()), zap.Bool("query", query))
return err
Expand Down

0 comments on commit b0f589e

Please sign in to comment.