From 755d16e82acf1ff52406944597ad82b19b6ce6da Mon Sep 17 00:00:00 2001 From: bb7133 Date: Tue, 15 Mar 2022 15:15:52 +0800 Subject: [PATCH] cherry pick #32809 to release-5.4 Signed-off-by: ti-srebot --- server/conn.go | 16 ++++++++++------ server/server.go | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/server/conn.go b/server/conn.go index 769fe7eb7e80f..f8fef4eafcbb3 100644 --- a/server/conn.go +++ b/server/conn.go @@ -1067,12 +1067,16 @@ func (cc *clientConn) Run(ctx context.Context) { if err != nil { if terror.ErrorNotEqual(err, io.EOF) { if netErr, isNetErr := errors.Cause(err).(net.Error); isNetErr && netErr.Timeout() { - idleTime := time.Since(start) - logutil.Logger(ctx).Info("read packet timeout, close this connection", - zap.Duration("idle", idleTime), - zap.Uint64("waitTimeout", waitTimeout), - zap.Error(err), - ) + if atomic.LoadInt32(&cc.status) == connStatusWaitShutdown { + logutil.Logger(ctx).Info("read packet timeout because of killed connection") + } else { + idleTime := time.Since(start) + logutil.Logger(ctx).Info("read packet timeout, close this connection", + zap.Duration("idle", idleTime), + zap.Uint64("waitTimeout", waitTimeout), + zap.Error(err), + ) + } } else { errStack := errors.ErrorStack(err) if !strings.Contains(errStack, "use of closed network connection") { diff --git a/server/server.go b/server/server.go index 2be15b20b7bf9..a81b4c3b74d6c 100644 --- a/server/server.go +++ b/server/server.go @@ -618,9 +618,6 @@ func (s *Server) ShowProcessList() map[uint64]*util.ProcessInfo { defer s.rwlock.RUnlock() rs := make(map[uint64]*util.ProcessInfo, len(s.clients)) for _, client := range s.clients { - if atomic.LoadInt32(&client.status) == connStatusWaitShutdown { - continue - } if pi := client.ctx.ShowProcess(); pi != nil { rs[pi.ID] = pi } @@ -693,6 +690,11 @@ func killConn(conn *clientConn) { if cancelFunc != nil { cancelFunc() } + if conn.bufReadConn != nil { + if err := conn.bufReadConn.SetReadDeadline(time.Now()); err != nil { + logutil.BgLogger().Warn("error setting read deadline for kill.", zap.Error(err)) + } + } } // KillAllConnections kills all connections when server is not gracefully shutdown.