Skip to content

fix(idempotency): prevent setInterval leakage across Next.js HMR (#1942) - #2054

Open
neverm1ndthat wants to merge 1 commit into
Commitlabs-Org:masterfrom
neverm1ndthat:fix/1941-1946-grantfox
Open

neverm1ndthat wants to merge 1 commit into
Commitlabs-Org:masterfrom
neverm1ndthat:fix/1941-1946-grantfox

Conversation

@neverm1ndthat

Copy link
Copy Markdown

Summary

Fixes Issue #1942: Module-level setInterval in src/lib/backend/idempotency.ts is never cleared

The Bug

The cleanup setInterval was guarded by a module-level let cleanupIntervalId === null check. In Next.js App Router with module hot-reload (HMR), the module scope is recreated on every file change - so cleanupIntervalId would reset to
ull and a brand-new interval would be registered every HMR cycle, while the old ones leaked forever.

The Fix

Replace the module-scoped let binding with a Symbol.for()-keyed reference on globalThis. This persists across HMR boundaries:

s const CLEANUP_INTERVAL_KEY = Symbol.for('commitlabs.idempotency.cleanupInterval'); declare global { var [CLEANUP_INTERVAL_KEY]?: ReturnType<typeof setInterval>; } if (typeof setInterval !== 'undefined' && typeof globalThis[CLEANUP_INTERVAL_KEY] === 'undefined') { globalThis[CLEANUP_INTERVAL_KEY] = setInterval(() => globalStore.cleanup(), 60_000); }

The existing clearCleanupInterval() export is preserved and now correctly reads from the global reference.

Commitlabs-Org#1942)

Use Symbol.for()-keyed global reference so the cleanup interval 
survives module hot-reload cycles. Previously the module-level 
'let cleanupIntervalId' binding would reset to null on each HMR 
tick, causing a new setInterval to be registered every reload.
@vercel

vercel Bot commented Oct 6, 2026

Copy link
Copy Markdown

@neverm1ndthat is attempting to deploy a commit to the 1nonly's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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