Skip to content

Conversation

@CybotTM
Copy link
Member

@CybotTM CybotTM commented Nov 27, 2025

Summary

Fix range loop modification bug in time-backwards handling code.

Problem

The for-range loop iterates over c.entries while calling Update(), which reorders elements via heap.Fix(). This could cause entries to be visited twice or skipped.

Solution

Iterate over a copy of the entries slice, ensuring all entries are checked exactly once.

Upstream Reference

Addresses robfig#480 - PR implementing time backwards handling. This fix improves the robustness of time-backwards scenarios.

Test plan

  • All existing tests pass with race detector
  • Change is defensive - only affects rare time-backwards scenario

Fixes #40

The time-backwards handling code iterates over entries while calling
Update(), which reorders the heap via heap.Fix(). This could cause
entries to be visited twice or skipped.

Fix by iterating over a copy of the entries slice, ensuring all
entries are checked exactly once regardless of heap reordering.

Fixes #40
@CybotTM CybotTM merged commit f8cadec into main Nov 27, 2025
12 checks passed
@CybotTM CybotTM deleted the fix/40-range-loop-modification branch November 27, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Range loop modification during time-backwards handling [MEDIUM]

2 participants