runtime: deltimer in time.go doesn't update the last after removing a timer #19887
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
https://github.com/golang/go/blob/master/src/runtime/time.go#L148
We remove the timer
t
at locationi
from the heaptimers.t
by replacingtimers.t[i]
with the last timer in the heap slice and then shrinking the slice. Then we need to shift it up/down to its correct location in the heap. In line 148 there is a short path that checks if it is already the last item in the heap slice.We have not updated the value of the variable
last
so thisif
will always fail and we will perform shift up/down even if it is the last item in the updated slice. If we want to avoid shift up/down in that case we should either update the value of the variablelast
bylast--
after line 147 or useif i != last-1 {
instead ofif i != last {
;However I think the short path might not actually work. The last item in the heap slice is not the largest item, even if its new location is the new last item of the slice it doesn't mean it is in the right location because it may need to move up, consider [0, 5, 2, 6, 7, 4] and assume we remove 7. if we don't perform a shift up/down we will end up with [0, 5, 2, 6, 4] which doesn't have the heap property as 4 is a child of 5 but is smaller than it. So I think we should just remove the
if
for the short path and always do shift up/down.The text was updated successfully, but these errors were encountered: