Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: Fix coroutine leak after kill remote connection #46035

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down