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: kill tidb [session id] can't stop executors and release resources quickly #9844

Merged
merged 16 commits into from
Apr 1, 2019
4 changes: 4 additions & 0 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type clientConn struct {
mu struct {
sync.RWMutex
cancelFunc context.CancelFunc
resultSets []ResultSet
}
}

Expand Down Expand Up @@ -1047,6 +1048,9 @@ func (cc *clientConn) handleQuery(ctx context.Context, sql string) (err error) {
metrics.ExecuteErrorCounter.WithLabelValues(metrics.ExecuteErrorToLabel(err)).Inc()
return errors.Trace(err)
}
cc.mu.Lock()
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
cc.mu.resultSets = rs
cc.mu.Unlock()
if rs != nil {
if len(rs) == 1 {
err = cc.writeResultset(ctx, rs[0], false, 0, 0)
Expand Down
6 changes: 6 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ func killConn(conn *clientConn, query bool) {
}

conn.mu.RLock()
for _, resultSet := range conn.mu.resultSets {
// resultSet.Close() is reentrant so it's safe to kill a same connID multiple times
zz-jason marked this conversation as resolved.
Show resolved Hide resolved
if err := resultSet.Close(); err != nil {
logutil.Logger(context.Background()).Error("close result set error", zap.Uint32("connID", conn.connectionID), zap.Error(err))
zz-jason marked this conversation as resolved.
Show resolved Hide resolved
}
}
cancelFunc := conn.mu.cancelFunc
conn.mu.RUnlock()
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
if cancelFunc != nil {
Expand Down