Skip to content

Commit

Permalink
tools: fix panic issue in tso bench
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <[email protected]>
  • Loading branch information
nolouch committed Jul 26, 2024
1 parent ca179e6 commit 2dccd58
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/pd-tso-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 2dccd58

Please sign in to comment.