diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 7eb82c99b25..6f70e6cfeaf 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -460,7 +460,14 @@ func (c *RaftCluster) runServiceCheckJob() { case <-schedulingTicker.C: c.checkSchedulingService() case <-tsoTicker.C: - c.checkTSOService() + // ensure raft cluster is running + // avoid unexpected startTSOJobsIfNeeded when raft cluster is stopping + // ref: https://github.com/tikv/pd/issues/8781 + c.RLock() + if c.running { + c.checkTSOService() + } + c.RUnlock() } } } @@ -488,6 +495,7 @@ func (c *RaftCluster) stopTSOJobsIfNeeded() error { return err } if allocator.IsInitialize() { + log.Info("closing the global TSO allocator") c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true) failpoint.Inject("updateAfterResetTSO", func() { allocator, _ := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation)