forked from robfig/cron
-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Description
Upstream Reference
Addresses robfig#480 - PR implementing time backwards handling.
Summary
The time-backwards handling code iterates over entries with a range loop while calling Update(), which modifies the underlying slice ordering.
Location
cron.go:277-284
for _, e := range c.entries {
if !e.Prev.IsZero() && e.Prev.After(now) {
e.Next = e.Schedule.Next(now)
c.entries.Update(e) // Calls heap.Fix which reorders elements
c.logger.Info("reschedule", ...)
}
}Problem
rangeiterates with original indicesUpdate()→heap.Fix()→Swap()reorders elements- After swaps, some entries may be visited twice or skipped
Impact
- Severity: Medium
- Only affects rare "time moved backwards" scenario (NTP correction, VM restore)
- Some entries may miss rescheduling during correction
- Heap remains structurally valid afterward
Fix Options
- Iterate over a copy of the entries
- Use index-based iteration accounting for swaps
- Collect entries to update first, then update in separate loop
// Option 1: Copy entries
entriesCopy := make([]*Entry, len(c.entries))
copy(entriesCopy, c.entries)
for _, e := range entriesCopy {
// ... update logic
}Validation
- Consensus: Disputed initially, resolved as valid bug with medium severity
Metadata
Metadata
Assignees
Labels
No labels