Skip to content

Commit

Permalink
server: return error on ping when in graceful shutdown (pingcap#58008)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Dec 14, 2024
1 parent 5637eaf commit 8c7f784
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/err/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

0 comments on commit 8c7f784

Please sign in to comment.