refactor(utils): add TimerRegistry for centralized timer cleanup (#4248)#4290
Merged
Conversation
Contributor
There was a problem hiding this comment.
π Review from Argus. Clean utility class, but found a regression.
Bug: quotaSweepInterval No Longer Cleared on Shutdown π
The shutdown block replaces all individual clearInterval() calls with timers.clearAll(), but quotaSweepInterval was never migrated to the TimerRegistry:
// Line ~1294 β still uses raw setInterval, NOT tracked:
const quotaSweepInterval = setInterval(() => routeCtx.quotas.sweep(), 5 * 60_000);Meanwhile, the old cleanup was removed:
- clearInterval(quotaSweepInterval);Result: quotaSweepInterval is now orphaned β it will NOT be cleared on shutdown, causing a timer leak. This is a regression from the current behavior.
Fix: Either:
- Replace with
timers.setInterval(...), or - Add
timers.track(quotaSweepInterval)after the assignment (likestaticPruneInterval)
What Looks Good β
- TimerRegistry class (60 lines) β clean, well-designed
- Auto-untrack on setTimeout fire β smart
- 137 lines of tests covering setTimeout, setInterval, clearAll, edge cases
track()method for externally-created handles β good forward-thinking- Bundle threshold bump 2370β2375 β reasonable
- shutdown path simplified nicely
Just need the quotaSweepInterval fix and this is good to merge.
Contributor
There was a problem hiding this comment.
β Approved. Clean TimerRegistry extraction.
Review summary:
- TimerRegistry class (60 lines): clean Set-based handle tracking, auto-untrack on timeout fire, clearAll uses clearTimeout for both types (safe in Node.js)
- 14 tests covering setTimeout, setInterval, clearTimeout, clearInterval, clearAll, activeCount, edge cases (idempotent clearAll, delay-0, double-clear)
- server.ts: 8 individual clearInterval calls replaced with single
timers.clearAll(), forceExitTimer intentionally untracked (safety net must survive clearAll) - staticPruneInterval tracked via
timers.track()for externally-created handles - Bundle threshold 2370β2375 to accommodate new utility
- All 9 merge gates passed β
Merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Centralizes all
setInterval/setTimeouthandles in aTimerRegistryutility for clean shutdown. Replaces 8 individualclearIntervalcalls with singletimers.clearAll().Closes #4248
Changes
src/utils/timer-registry.ts(67 lines) βTimerRegistryclasssetTimeout/setIntervalwrappers with auto-trackingclearTimeout/clearInterval/clearAlltrack()for externally-created handlesactiveCountgettersrc/__tests__/timer-registry.test.ts(137 lines) β 14 testssrc/server.ts(+214/-19)setIntervalcalls βtimers.setInterval()configReloadTimerβtimers.setTimeout()/timers.clearTimeout()clearInterval+ 1clearTimeoutβtimers.clearAll()staticPruneIntervaltracked viatimers.track()(externally-created handle)forceExitTimerintentionally NOT tracked β safety net must surviveclearAll()Review feedback addressed (from previous #4272)
timers.track()(no dummy no-op interval)clearAll()per reviewer concernfeat:torefactor:β no semver bump gate issueVerification
Closes #4248