fix(clock): don't fire future timers during ProcessEvents#252
fix(clock): don't fire future timers during ProcessEvents#252denisraison wants to merge 1 commit into
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR modifies clock event simulation to prevent unrelated future-scheduled timers from executing during event processing. A new 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ 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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
Problem
ProcessEventsis supposed to drain pending async work (microtasks, fetches, posted events). It currently callsClock.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
ProcessEventswas 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 whenAdvancereaches 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.