Skip to content

fix(clock): don't fire future timers during ProcessEvents#252

Open
denisraison wants to merge 1 commit into
gost-dom:mainfrom
denisraison:fix/clock-process-events-future-timers
Open

fix(clock): don't fire future timers during ProcessEvents#252
denisraison wants to merge 1 commit into
gost-dom:mainfrom
denisraison:fix/clock-process-events-future-timers

Conversation

@denisraison
Copy link
Copy Markdown

Problem

ProcessEvents is supposed to drain pending async work (microtasks, fetches, posted events). It currently calls Clock.RunAll, which fast-forwards through every scheduled timer regardless of when it was due.

I hit this running an htmx app under gost-dom: htmx schedules a 60s defensive abort timer when a request starts, and ProcessEvents was firing it mid-request, cancelling fetches still in flight.

Fix

Introduce runDueTasks: drain microtasks and any timers whose scheduled time has already passed, but leave future-scheduled timers alone. They still fire when Advance reaches them, same as before.

Includes a regression test covering the htmx-style scenario (scheduled-but-not-due timer should not fire during ProcessEvents).

Notes

Small, isolated change in internal/clock. No public API change.

ProcessEvents waits for pending async work (microtasks, fetches, posted
events). It used to drive Clock.RunAll, which fast-forwards through every
scheduled timer regardless of when they were due. That fired things like
htmx's 60s defensive abort timer mid-request, cancelling fetches that
were still in flight.

Introduce runDueTasks: drain microtasks and any timers whose scheduled
time has already passed, but leave future-scheduled timers alone. They
still fire when Advance reaches their time, as before.

Adds a regression test covering the htmx-style scenario.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 424f36c3-5bce-40b5-afa8-ed473926df99

📥 Commits

Reviewing files that changed from the base of the PR and between 40953c9 and d242a3f.

📒 Files selected for processing (2)
  • internal/clock/clock.go
  • internal/clock/clock_test.go

Walkthrough

This PR modifies clock event simulation to prevent unrelated future-scheduled timers from executing during event processing. A new runDueTasks helper runs microtasks and only those timer tasks already due by the current simulated time, replacing the prior RunAll behavior that executed all queued timers. The method ProcessEventsWhile now uses this new helper to make forward progress on real async work without fast-forwarding through long-delay timeouts. A test verifies that future timers armed separately from events do not fire during ProcessEvents and only execute when the clock is explicitly advanced.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: preventing future timers from firing during ProcessEvents, which is the core fix addressed in this PR.
Description check ✅ Passed The description is well-related to the changeset, clearly explaining the problem (ProcessEvents firing future timers prematurely), the solution (runDueTasks helper), and the testing approach.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant