mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user