Skip to content

Commit c1ee9cf

Browse files
authoredDec 20, 2024
resource control: fix unsafe usage of time.After and timer.Reset (#8928)
close #8876 Signed-off-by: lhy1024 <admin@liudos.us>
1 parent 03488a4 commit c1ee9cf

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
 

‎client/resource_group/controller/controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
294294
log.Warn("watch resource group meta failed", zap.Error(err))
295295
timerutil.SafeResetTimer(watchRetryTimer, watchRetryInterval)
296296
failpoint.Inject("watchStreamError", func() {
297-
watchRetryTimer.Reset(20 * time.Millisecond)
297+
timerutil.SafeResetTimer(watchRetryTimer, 20*time.Millisecond)
298298
})
299299
}
300300
}
@@ -338,7 +338,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
338338
watchMetaChannel = nil
339339
timerutil.SafeResetTimer(watchRetryTimer, watchRetryInterval)
340340
failpoint.Inject("watchStreamError", func() {
341-
watchRetryTimer.Reset(20 * time.Millisecond)
341+
timerutil.SafeResetTimer(watchRetryTimer, 20*time.Millisecond)
342342
})
343343
continue
344344
}
@@ -374,7 +374,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
374374
watchConfigChannel = nil
375375
timerutil.SafeResetTimer(watchRetryTimer, watchRetryInterval)
376376
failpoint.Inject("watchStreamError", func() {
377-
watchRetryTimer.Reset(20 * time.Millisecond)
377+
timerutil.SafeResetTimer(watchRetryTimer, 20*time.Millisecond)
378378
})
379379
continue
380380
}
@@ -527,7 +527,7 @@ func (c *ResourceGroupsController) sendTokenBucketRequests(ctx context.Context,
527527
ClientUniqueId: c.clientUniqueID,
528528
}
529529
if c.ruConfig.DegradedModeWaitDuration > 0 && c.responseDeadlineCh == nil {
530-
c.run.responseDeadline.Reset(c.ruConfig.DegradedModeWaitDuration)
530+
timerutil.SafeResetTimer(c.run.responseDeadline, c.ruConfig.DegradedModeWaitDuration)
531531
c.responseDeadlineCh = c.run.responseDeadline.C
532532
}
533533
go func() {

‎client/retry/backoff.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/pingcap/errors"
2525
"github.com/pingcap/failpoint"
2626
"github.com/pingcap/log"
27+
"github.com/tikv/pd/client/timerutil"
2728
"go.uber.org/zap"
2829
)
2930

@@ -86,7 +87,7 @@ func (bo *Backoffer) Exec(
8687
if after == nil {
8788
after = time.NewTimer(currentInterval)
8889
} else {
89-
after.Reset(currentInterval)
90+
timerutil.SafeResetTimer(after, currentInterval)
9091
}
9192
select {
9293
case <-ctx.Done():

0 commit comments

Comments
 (0)