diff --git a/server/conn.go b/server/conn.go index 41133a9bec358..44f43920a8b37 100644 --- a/server/conn.go +++ b/server/conn.go @@ -1111,6 +1111,8 @@ func (cc *clientConn) Run(ctx context.Context) { // by CAS operation, it would then take some actions accordingly. for { // Close connection between txn when we are going to shutdown server. + // Note the current implementation when shutting down, for an idle connection, the connection may block at readPacket() + // consider provider a way to close the connection directly after sometime if we can not read any data. if cc.server.inShutdownMode.Load() { if !cc.ctx.GetSessionVars().InTxn() { return diff --git a/tidb-server/main.go b/tidb-server/main.go index e5ead347a1841..c816e5254508b 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -836,17 +836,15 @@ func closeDomainAndStorage(storage kv.Storage, dom *domain.Domain) { terror.Log(errors.Trace(err)) } +// The amount of time we wait for the ongoing txt to finished. +// We should better provider a dynamic way to set this value. var gracefulCloseConnectionsTimeout = 15 * time.Second -func cleanup(svr *server.Server, storage kv.Storage, dom *domain.Domain, graceful bool) { +func cleanup(svr *server.Server, storage kv.Storage, dom *domain.Domain, _ bool) { dom.StopAutoAnalyze() - var drainClientWait time.Duration - if graceful { - drainClientWait = 1<<63 - 1 - } else { - drainClientWait = gracefulCloseConnectionsTimeout - } + drainClientWait := gracefulCloseConnectionsTimeout + cancelClientWait := time.Second * 1 svr.DrainClients(drainClientWait, cancelClientWait)