Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 1538f09

Browse files
authored
server: kill queries on connection closed (#769)
server: kill queries on connection closed
2 parents 8702d43 + d33b54c commit 1538f09

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

server/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"sync"
99
"time"
1010

11-
errors "gopkg.in/src-d/go-errors.v1"
1211
sqle "github.com/src-d/go-mysql-server"
1312
"github.com/src-d/go-mysql-server/auth"
1413
"github.com/src-d/go-mysql-server/sql"
14+
errors "gopkg.in/src-d/go-errors.v1"
1515

1616
"github.com/sirupsen/logrus"
1717
"vitess.io/vitess/go/mysql"
@@ -62,6 +62,9 @@ func (h *Handler) ConnectionClosed(c *mysql.Conn) {
6262
delete(h.c, c.ConnectionID)
6363
h.mu.Unlock()
6464

65+
// If connection was closed, kill only its associated queries.
66+
h.e.Catalog.ProcessList.KillOnlyQueries(c.ConnectionID)
67+
6568
if err := h.e.Catalog.UnlockTables(nil, c.ConnectionID); err != nil {
6669
logrus.Errorf("unable to unlock tables on session close: %s", err)
6770
}

sql/processlist.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (pl *ProcessList) AddProgressItem(pid uint64, name string, total int64) {
156156
}
157157
}
158158

159-
// Kill terminates all queries for a given connection
159+
// Kill terminates all queries for a given connection id.
160160
func (pl *ProcessList) Kill(connID uint32) {
161161
pl.mu.Lock()
162162
defer pl.mu.Unlock()
@@ -170,6 +170,21 @@ func (pl *ProcessList) Kill(connID uint32) {
170170
}
171171
}
172172

173+
// KillOnlyQueries kills all queries, but not index creation queries, for a
174+
// given connection id.
175+
func (pl *ProcessList) KillOnlyQueries(connID uint32) {
176+
pl.mu.Lock()
177+
defer pl.mu.Unlock()
178+
179+
for pid, proc := range pl.procs {
180+
if proc.Connection == connID && proc.Type == QueryProcess {
181+
logrus.Infof("kill query: pid %d", pid)
182+
proc.Done()
183+
delete(pl.procs, pid)
184+
}
185+
}
186+
}
187+
173188
// Done removes the finished process with the given pid from the process list.
174189
// If the process does not exist, it will do nothing.
175190
func (pl *ProcessList) Done(pid uint64) {

0 commit comments

Comments
 (0)