Skip to content

Commit da362ae

Browse files
committed
[Heartbeat] Use timer.reset now that golang has been updated
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.
1 parent 897df4c commit da362ae

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

heartbeat/scheduler/timerqueue/queue.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (tq *TimerQueue) Start() {
8888
if tq.th.Len() > 0 {
8989
nr := tq.th[0].runAt
9090
tq.nextRunAt = &nr
91-
tq.timer = time.NewTimer(time.Until(nr))
91+
tq.timer.Reset(time.Until(nr))
9292
} else {
9393
tq.timer.Stop()
9494
tq.nextRunAt = nil
@@ -107,18 +107,7 @@ func (tq *TimerQueue) pushInternal(tt *timerTask) {
107107
if tq.nextRunAt != nil && !tq.timer.Stop() {
108108
<-tq.timer.C
109109
}
110-
// Originally the line below this comment was
111-
//
112-
// tq.timer.Reset(time.Until(tt.runAt))
113-
//
114-
// however this broke in go1.16rc1, specifically on the commit b4b014465216790e01aa66f9120d03230e4aff46
115-
//, specifically on this line:
116-
// https://github.com/golang/go/commit/b4b014465216790e01aa66f9120d03230e4aff46#diff-73699b6edfe5dbb3f6824e66bb3566bce9405e9a8c810cac55c8199459f0ac19R652
117-
// where some nice new optimizations don't actually work reliably
118-
// This can be worked around by instantiating a new timer rather than resetting the timer.
119-
// since that internally calls deltimer in runtime/timer.go rather than modtimer,
120-
// I suspect that the problem is in modtimer's setting of &pp.timerModifiedEarliest
121-
tq.timer = time.NewTimer(time.Until(tt.runAt))
110+
tq.timer.Reset(time.Until(tt.runAt))
122111
tq.nextRunAt = &tt.runAt
123112
}
124113
}

0 commit comments

Comments
 (0)