Skip to content

Commit

Permalink
[Heartbeat] Use timer.reset now that golang has been updated (#29729) (
Browse files Browse the repository at this point in the history
…#29733)

Undoes https://github.com/elastic/beats/pull/27006/files (while preserving the new test), and also cleaning up the syntax using `time.Until`.

Since the The golang bug I reported in golang/go#47329 has been fixed since somewhere in go 1.16.x (it's hard to track the exact version). This should be backported to 7.16.x since that already uses go 1.17.x and is safe.

(cherry picked from commit 7b095da)

Co-authored-by: Andrew Cholakian <[email protected]>
  • Loading branch information
mergify[bot] and andrewvc authored Jan 14, 2022
1 parent 7b0c1df commit 6c305d9
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions heartbeat/scheduler/timerqueue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (tq *TimerQueue) Start() {
if tq.th.Len() > 0 {
nr := tq.th[0].runAt
tq.nextRunAt = &nr
tq.timer = time.NewTimer(time.Until(nr))
tq.timer.Reset(time.Until(nr))
} else {
tq.timer.Stop()
tq.nextRunAt = nil
Expand All @@ -107,18 +107,7 @@ func (tq *TimerQueue) pushInternal(tt *timerTask) {
if tq.nextRunAt != nil && !tq.timer.Stop() {
<-tq.timer.C
}
// Originally the line below this comment was
//
// tq.timer.Reset(time.Until(tt.runAt))
//
// however this broke in go1.16rc1, specifically on the commit b4b014465216790e01aa66f9120d03230e4aff46
//, specifically on this line:
// https://github.com/golang/go/commit/b4b014465216790e01aa66f9120d03230e4aff46#diff-73699b6edfe5dbb3f6824e66bb3566bce9405e9a8c810cac55c8199459f0ac19R652
// where some nice new optimizations don't actually work reliably
// This can be worked around by instantiating a new timer rather than resetting the timer.
// since that internally calls deltimer in runtime/timer.go rather than modtimer,
// I suspect that the problem is in modtimer's setting of &pp.timerModifiedEarliest
tq.timer = time.NewTimer(time.Until(tt.runAt))
tq.timer.Reset(time.Until(tt.runAt))
tq.nextRunAt = &tt.runAt
}
}
Expand Down

0 comments on commit 6c305d9

Please sign in to comment.