diff --git a/pkg/cache/ttl.go b/pkg/cache/ttl.go index 11dd1248370..9baafc1d4b0 100644 --- a/pkg/cache/ttl.go +++ b/pkg/cache/ttl.go @@ -19,6 +19,7 @@ import ( "time" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/logutil" "github.com/tikv/pd/pkg/syncutil" "go.uber.org/zap" ) @@ -142,6 +143,7 @@ func (c *ttlCache) Clear() { } func (c *ttlCache) doGC() { + defer logutil.LogPanic() ticker := time.NewTicker(c.gcInterval) defer ticker.Stop() diff --git a/pkg/systimemon/systimemon.go b/pkg/systimemon/systimemon.go index a3124312fa2..ad3929caea9 100644 --- a/pkg/systimemon/systimemon.go +++ b/pkg/systimemon/systimemon.go @@ -20,11 +20,13 @@ import ( "github.com/pingcap/log" "github.com/tikv/pd/pkg/errs" + "github.com/tikv/pd/pkg/logutil" "go.uber.org/zap" ) // StartMonitor calls systimeErrHandler if system time jump backward. func StartMonitor(ctx context.Context, now func() time.Time, systimeErrHandler func()) { + defer logutil.LogPanic() log.Info("start system time monitor") tick := time.NewTicker(100 * time.Millisecond) defer tick.Stop() diff --git a/server/election/lease.go b/server/election/lease.go index cb5d13ddb33..4e368b98361 100644 --- a/server/election/lease.go +++ b/server/election/lease.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/log" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/etcdutil" + "github.com/tikv/pd/pkg/logutil" "github.com/tikv/pd/pkg/typeutil" "go.etcd.io/etcd/clientv3" "go.uber.org/zap" @@ -129,6 +130,7 @@ func (l *lease) keepAliveWorker(ctx context.Context, interval time.Duration) <-c ch := make(chan time.Time) go func() { + defer logutil.LogPanic() ticker := time.NewTicker(interval) defer ticker.Stop() @@ -137,6 +139,7 @@ func (l *lease) keepAliveWorker(ctx context.Context, interval time.Duration) <-c for { go func() { + defer logutil.LogPanic() start := time.Now() ctx1, cancel := context.WithTimeout(ctx, l.leaseTimeout) defer cancel() diff --git a/server/region_syncer/client.go b/server/region_syncer/client.go index 3f2419ad720..b7be4a27061 100644 --- a/server/region_syncer/client.go +++ b/server/region_syncer/client.go @@ -24,6 +24,7 @@ import ( "github.com/pingcap/log" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/grpcutil" + "github.com/tikv/pd/pkg/logutil" "github.com/tikv/pd/server/core" "go.uber.org/zap" "google.golang.org/grpc" @@ -116,6 +117,7 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) { ctx := s.mu.clientCtx go func() { + defer logutil.LogPanic() defer s.wg.Done() // used to load region from kv storage to cache storage. bc := s.server.GetBasicCluster() diff --git a/server/tso/allocator_manager.go b/server/tso/allocator_manager.go index f0689ee4713..9746f41b35a 100644 --- a/server/tso/allocator_manager.go +++ b/server/tso/allocator_manager.go @@ -30,6 +30,7 @@ import ( "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/pkg/grpcutil" + "github.com/tikv/pd/pkg/logutil" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/syncutil" "github.com/tikv/pd/server/config" @@ -341,6 +342,7 @@ func (am *AllocatorManager) getLocalTSOAllocatorPath() string { // similar logic with leaderLoop in server/server.go func (am *AllocatorManager) allocatorLeaderLoop(ctx context.Context, allocator *LocalTSOAllocator) { + defer logutil.LogPanic() defer log.Info("server is closed, return local tso allocator leader loop", zap.String("dc-location", allocator.GetDCLocation()), zap.String("local-tso-allocator-name", am.member.Member().Name)) @@ -592,6 +594,7 @@ func (am *AllocatorManager) allocatorUpdater() { // updateAllocator is used to update the allocator in the group. func (am *AllocatorManager) updateAllocator(ag *allocatorGroup) { + defer logutil.LogPanic() defer am.wg.Done() select { case <-ag.ctx.Done(): @@ -642,6 +645,7 @@ func (am *AllocatorManager) allocatorPatroller(serverCtx context.Context) { // ClusterDCLocationChecker collects all dc-locations of a cluster, computes some related info // and stores them into the DCLocationInfo, then finally writes them into am.mu.clusterDCLocations. func (am *AllocatorManager) ClusterDCLocationChecker() { + defer logutil.LogPanic() // Wait for the PD leader to be elected out. if am.member.GetLeader() == nil { return diff --git a/server/tso/global_allocator.go b/server/tso/global_allocator.go index 02d7b7438c8..6c69c0a0cc7 100644 --- a/server/tso/global_allocator.go +++ b/server/tso/global_allocator.go @@ -25,6 +25,7 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" "github.com/tikv/pd/pkg/errs" + "github.com/tikv/pd/pkg/logutil" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/tsoutil" "github.com/tikv/pd/pkg/typeutil" @@ -334,6 +335,7 @@ func (gta *GlobalTSOAllocator) SyncMaxTS( // Send SyncMaxTSRequest to all allocator leaders concurrently. wg.Add(1) go func(ctx context.Context, conn *grpc.ClientConn, respCh chan<- *syncResp) { + defer logutil.LogPanic() defer wg.Done() syncMaxTSResp := &syncResp{} syncCtx, cancel := context.WithTimeout(ctx, rpcTimeout)