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

server: close connection when tidb server closed. #8446

Merged
merged 5 commits into from Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions server/server.go
Expand Up @@ -351,6 +351,10 @@ func (s *Server) Kill(connectionID uint64, query bool) {
return
}

killConn(conn, query)
}

func killConn(conn *clientConn, query bool) {
conn.mu.RLock()
cancelFunc := conn.mu.cancelFunc
conn.mu.RUnlock()
Expand All @@ -365,6 +369,17 @@ func (s *Server) Kill(connectionID uint64, query bool) {
}
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
}

// KillAllConnections kills all connections when server is not gracefully shutdown.
func (s *Server) KillAllConnections() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call cancel function in clientConn.dispatch can make the connection return?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call ctx.cancel will cancel the current execution, atomic.StoreInt32(&conn.status, connStatusWaitShutdown) will make the connection close itself later.

s.rwlock.Lock()
defer s.rwlock.Unlock()
log.Info("[server] kill all connections.")

for _, conn := range s.clients {
killConn(conn, false)
}
}

// GracefulDown waits all clients to close.
func (s *Server) GracefulDown() {
log.Info("[server] graceful shutdown.")
Expand Down
2 changes: 2 additions & 0 deletions tidb-server/main.go
Expand Up @@ -513,6 +513,8 @@ func closeDomainAndStorage() {
func cleanup() {
if graceful {
svr.GracefulDown()
} else {
svr.KillAllConnections()
}
closeDomainAndStorage()
}