Conversation
The ESM loader replaces readFileUtf8 (readFileSync on older Node) on the internal fs binding with a function that reads through fs.readFileSync. For files outside of zip archives fs.readFileSync calls that same binding method, so each read recursed until the stack overflowed; the RangeError was swallowed and the innermost call fell back to the original binding. Calls nested within the patched function now go straight to the original binding. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
What's the problem this PR addresses?
When the internal translators are loaded before our fs patch (see #5961),
the ESM loader replaces
readFileUtf8(orreadFileSyncon older Nodeversions) on the internal
fsbinding with a function that reads thefile through
fs.readFileSync. For files that aren't in a zip archive,fs.readFileSyncreads them through that same binding method, which isnow the patched one. Each such read recurses until the stack overflows;
the
RangeErroris swallowed by thecatch, and the innermost callfalls back to the original binding, whose result is then returned
through every level of the recursion.
The result is right, but every read of a file outside of the cache costs
thousands of frames for nothing.
How did you fix it?
The patched function keeps a flag while it reads through
fs.readFileSync. Calls nested within it go straight to the originalbinding, which is where the recursion used to end. Files inside zip
archives are still served by the patched
fs, and errors still comefrom the original binding.
Checklist