diff --git a/pkg/statistics/hot_cache.go b/pkg/statistics/hot_cache.go index 3f076734a7b..86f7d7d6b08 100644 --- a/pkg/statistics/hot_cache.go +++ b/pkg/statistics/hot_cache.go @@ -113,18 +113,20 @@ func (w *HotCache) IsRegionHot(region *core.RegionInfo, minHotDegree int) bool { succ1 := w.CheckWriteAsync(checkRegionHotWriteTask) succ2 := w.CheckReadAsync(checkRegionHotReadTask) if succ1 && succ2 { - select { - case <-w.ctx.Done(): - return false - case r := <-retWrite: - return r - case r := <-retRead: - return r - } + return waitRet(w.ctx, retWrite) || waitRet(w.ctx, retRead) } return false } +func waitRet(ctx context.Context, ret chan bool) bool { + select { + case <-ctx.Done(): + return false + case r := <-ret: + return r + } +} + // GetHotPeerStat returns hot peer stat with specified regionID and storeID. func (w *HotCache) GetHotPeerStat(kind utils.RWType, regionID, storeID uint64) *HotPeerStat { ret := make(chan *HotPeerStat, 1)