diff --git a/tools/pd-tso-bench/main.go b/tools/pd-tso-bench/main.go index 3726373779e..1e59dfd2a2a 100644 --- a/tools/pd-tso-bench/main.go +++ b/tools/pd-tso-bench/main.go @@ -386,20 +386,27 @@ func reqWorker(ctx context.Context, pdClients []pd.Client, clientIdx int, durCh var ticker *time.Ticker if *maxTSOSendIntervalMilliseconds > 0 { sleepBeforeGetTS := time.Duration(rand.Intn(*maxTSOSendIntervalMilliseconds)) * time.Millisecond - ticker = time.NewTicker(sleepBeforeGetTS) - select { - case <-reqCtx.Done(): - case <-ticker.C: - totalSleepBeforeGetTS += sleepBeforeGetTS + if sleepBeforeGetTS > 0 { + ticker = time.NewTicker(sleepBeforeGetTS) + select { + case <-reqCtx.Done(): + case <-ticker.C: + totalSleepBeforeGetTS += sleepBeforeGetTS + } } } _, _, err = pdCli.GetLocalTS(reqCtx, *dcLocation) if errors.Cause(err) == context.Canceled { - ticker.Stop() + if ticker != nil { + ticker.Stop() + } + return } if err == nil { - ticker.Stop() + if ticker != nil { + ticker.Stop() + } break } log.Error(fmt.Sprintf("%v", err))