Skip to content

Commit

Permalink
Merge branch 'release-2.1' of https://github.com/pingcap/tidb into 86…
Browse files Browse the repository at this point in the history
…20-2.1
  • Loading branch information
crazycs520 committed Dec 18, 2018
2 parents a494587 + 9f6ec69 commit cb10fc1
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 cb10fc1

Please sign in to comment.