Fix memory leak in dev mode caused by fast-set-immediate#89779
Merged
Conversation
Contributor
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Contributor
Tests Passed |
Contributor
Author
|
The test that failed here on CI is green for me locally, is the test flaky or am I doing something wrong? I ran |
Contributor
Author
|
Gentle nudge - I don't have the rights to rerun the CI and I can't reproduce this failure locally. Could someone help me figure out if it's a flaky test or whether this PR broke something? |
lubieowoce
approved these changes
Feb 12, 2026
Member
|
Looks good, thanks! I'll spin CI, hopefully this is just something transient / unrelated flakeage. |
67d26a1 to
a7d756c
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Fixes dev-time memory retention in
fast-set-immediatecaused by module re-evaluation chaining patched globals.Root Cause
In dev/HMR,
fast-set-immediate.externalcan be re-evaluated multiple times.On each evaluation, it captured
globalThis.setImmediate,globalThis.clearImmediate, andprocess.nextTickas “originals”. If those were already patched, new patched closures referenced older patched closures, retaining old module graphs.I have 2GB local heapdump from a few minutes before the local dev server crashed OOM that looks like this because of it:

What Changed
globalThis:Symbol.for('next.fast-set-immediate.originals')originalSetImmediate,originalClearImmediate, andoriginalNextTicknow always resolve from that base sentinel, not from currently patched globals.install()still runs at module loadDANGEROUSLY_runPendingImmediatesAfterCurrentTask,expectNoPendingImmediates, andunpatchedSetImmediateexports remain availableTests
module re-evaluationtest now verifiesunpatchedSetImmediateremains bound to the same base/original function across repeatedjest.resetModules()reloads, and is not rebound to the previously patched global.