Skip to content

Commit

Permalink
resource control: fix unsafe usage of time.After and timer.Reset (#8928)
Browse files Browse the repository at this point in the history
close #8876

Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 authored Dec 20, 2024
1 parent 03488a4 commit c1ee9cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions client/resource_group/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
log.Warn("watch resource group meta failed", zap.Error(err))
timerutil.SafeResetTimer(watchRetryTimer, watchRetryInterval)
failpoint.Inject("watchStreamError", func() {
watchRetryTimer.Reset(20 * time.Millisecond)
timerutil.SafeResetTimer(watchRetryTimer, 20*time.Millisecond)
})
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
watchMetaChannel = nil
timerutil.SafeResetTimer(watchRetryTimer, watchRetryInterval)
failpoint.Inject("watchStreamError", func() {
watchRetryTimer.Reset(20 * time.Millisecond)
timerutil.SafeResetTimer(watchRetryTimer, 20*time.Millisecond)
})
continue
}
Expand Down Expand Up @@ -374,7 +374,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
watchConfigChannel = nil
timerutil.SafeResetTimer(watchRetryTimer, watchRetryInterval)
failpoint.Inject("watchStreamError", func() {
watchRetryTimer.Reset(20 * time.Millisecond)
timerutil.SafeResetTimer(watchRetryTimer, 20*time.Millisecond)
})
continue
}
Expand Down Expand Up @@ -527,7 +527,7 @@ func (c *ResourceGroupsController) sendTokenBucketRequests(ctx context.Context,
ClientUniqueId: c.clientUniqueID,
}
if c.ruConfig.DegradedModeWaitDuration > 0 && c.responseDeadlineCh == nil {
c.run.responseDeadline.Reset(c.ruConfig.DegradedModeWaitDuration)
timerutil.SafeResetTimer(c.run.responseDeadline, c.ruConfig.DegradedModeWaitDuration)
c.responseDeadlineCh = c.run.responseDeadline.C
}
go func() {
Expand Down
3 changes: 2 additions & 1 deletion client/retry/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
"github.com/tikv/pd/client/timerutil"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -86,7 +87,7 @@ func (bo *Backoffer) Exec(
if after == nil {
after = time.NewTimer(currentInterval)
} else {
after.Reset(currentInterval)
timerutil.SafeResetTimer(after, currentInterval)
}
select {
case <-ctx.Done():
Expand Down

0 comments on commit c1ee9cf

Please sign in to comment.