diff --git a/errors.toml b/errors.toml index f8567cca42a7b..b5a728cb2d7e8 100644 --- a/errors.toml +++ b/errors.toml @@ -2936,6 +2936,11 @@ error = ''' Access denied for user '%-.48s'@'%-.255s' (using password: %s) ''' +["server:1053"] +error = ''' +Server shutdown in progress +''' + ["server:1148"] error = ''' The used command is not allowed with this MySQL version diff --git a/pkg/server/conn.go b/pkg/server/conn.go index 00665bdd88eda..6604d8c5f5415 100644 --- a/pkg/server/conn.go +++ b/pkg/server/conn.go @@ -1390,7 +1390,10 @@ func (cc *clientConn) dispatch(ctx context.Context, data []byte) error { return cc.writeStats(ctx) // ComProcessInfo, ComConnect, ComProcessKill, ComDebug case mysql.ComPing: - return cc.writeOK(ctx) + if cc.server.health.Load() { + return cc.writeOK(ctx) + } + return servererr.ErrServerShutdown case mysql.ComChangeUser: return cc.handleChangeUser(ctx, data) // ComBinlogDump, ComTableDump, ComConnectOut, ComRegisterSlave diff --git a/pkg/server/conn_test.go b/pkg/server/conn_test.go index 341404ef282eb..03b81fb0fa043 100644 --- a/pkg/server/conn_test.go +++ b/pkg/server/conn_test.go @@ -613,6 +613,11 @@ func testDispatch(t *testing.T, inputs []dispatchInput, capability uint32) { cfg.Status.ReportStatus = false server, err := NewServer(cfg, tidbdrv) require.NoError(t, err) + + // Set healthy. This is used by graceful shutdown + // and is used in the response for ComPing and the + // /status HTTP endpoint + server.health.Store(true) defer server.Close() cc := &clientConn{ diff --git a/pkg/server/err/error.go b/pkg/server/err/error.go index 952811951147c..5f6e854e7582d 100644 --- a/pkg/server/err/error.go +++ b/pkg/server/err/error.go @@ -44,4 +44,6 @@ var ( ErrNetPacketTooLarge = dbterror.ClassServer.NewStd(errno.ErrNetPacketTooLarge) // ErrMustChangePassword is returned when the user must change the password. ErrMustChangePassword = dbterror.ClassServer.NewStd(errno.ErrMustChangePassword) + // ErrServerShutdown is returned when the server is shutting down. + ErrServerShutdown = dbterror.ClassServer.NewStd(errno.ErrServerShutdown) )