Skip to content

Commit

Permalink
server: fix incorrect setting of health status (#51595) (#51624)
Browse files Browse the repository at this point in the history
close #51596
  • Loading branch information
ti-chi-bot committed Mar 21, 2024
1 parent 1c78eed commit 5bc98af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ go_download_sdk(
"https://mirrors.aliyun.com/golang/{}",
"https://dl.google.com/go/{}",
],
version = "1.20.11",
version = "1.20.14",
)

go_register_toolchains(
Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {
clients: make(map[uint64]*clientConn),
globalConnID: util.NewGlobalConnID(0, true),
internalSessions: make(map[interface{}]struct{}, 100),
health: uatomic.NewBool(true),
health: uatomic.NewBool(false),
inShutdownMode: uatomic.NewBool(false),
printMDLLogTime: time.Now(),
}
Expand Down Expand Up @@ -434,6 +434,7 @@ func (s *Server) Run(dom *domain.Domain) error {
if RunInGoTest && !isClosed(RunInGoTestChan) {
close(RunInGoTestChan)
}
s.health.Store(true)
err = <-errChan
if err != nil {
return err
Expand Down
22 changes: 22 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2655,3 +2655,25 @@ func (cli *testServerClient) RunTestStmtCountLimit(t *testing.T) {
require.Equal(t, 5, count)
})
}

func TestSeverHealth(t *testing.T) {
RunInGoTestChan = make(chan struct{})
RunInGoTest = true
store := testkit.CreateMockStore(t)
tidbdrv := NewTiDBDriver(store)
cfg := newTestConfig()
cfg.Port, cfg.Status.StatusPort = 0, 0
cfg.Status.ReportStatus = false
server, err := NewServer(cfg, tidbdrv)
require.NoError(t, err)
require.False(t, server.health.Load(), "server should not be healthy")
go func() {
err = server.Run(nil)
require.NoError(t, err)
}()
defer server.Close()
for range RunInGoTestChan {
// wait for server to be healthy
}
require.True(t, server.health.Load(), "server should be healthy")
}

0 comments on commit 5bc98af

Please sign in to comment.