Skip to content

Commit

Permalink
server: close all connection directly when terminate tidb (#8692) (#8707
Browse files Browse the repository at this point in the history
)
  • Loading branch information
crazycs520 authored and zz-jason committed Dec 17, 2018
1 parent 990f859 commit 9f6ec69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func (cc *clientConn) Close() error {
delete(cc.server.clients, cc.connectionID)
connections := len(cc.server.clients)
cc.server.rwlock.Unlock()
return closeConn(cc, connections)
}

func closeConn(cc *clientConn, connections int) error {
metrics.ConnGauge.Set(float64(connections))
err := cc.bufReadConn.Close()
terror.Log(errors.Trace(err))
Expand All @@ -162,6 +166,11 @@ func (cc *clientConn) Close() error {
return nil
}

func (cc *clientConn) closeWithoutLock() error {
delete(cc.server.clients, cc.connectionID)
return closeConn(cc, len(cc.server.clients))
}

// writeInitialHandshake sends server version, connection ID, server capability, collation, server status
// and auth salt to the client.
func (cc *clientConn) writeInitialHandshake() error {
Expand Down
9 changes: 8 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,14 @@ func (s *Server) KillAllConnections() {
log.Info("[server] kill all connections.")

for _, conn := range s.clients {
killConn(conn, false)
atomic.StoreInt32(&conn.status, connStatusShutdown)
terror.Log(errors.Trace(conn.closeWithoutLock()))
conn.mu.RLock()
cancelFunc := conn.mu.cancelFunc
conn.mu.RUnlock()
if cancelFunc != nil {
cancelFunc()
}
}
}

Expand Down

0 comments on commit 9f6ec69

Please sign in to comment.