fix: prevent double-insertion of auto-advance timer

Add check to scheduleAutoAdvanceTimer to prevent duplicate insertion
when useFakeTimers() is called multiple times. The timer is only
inserted if in_heap is .none.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-27 09:43:08 +00:00
parent a481971052
commit a89dcc1f75

View File

@@ -229,6 +229,9 @@ fn scheduleAutoAdvanceTimer(this: *FakeTimers, vm: *jsc.VirtualMachine) void {
const interval_ms = this.#auto_advance_interval_ms;
if (interval_ms == 0) return;
// Prevent double-insertion if timer is already scheduled
if (this.#auto_advance_timer.in_heap != .none) return;
const now = bun.timespec.now(.force_real_time);
this.#auto_advance_timer.next = now.addMs(interval_ms);
this.#auto_advance_timer.state = .PENDING;