-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using custom loaders results in a load loop / OOM #47566
Comments
--require
and --loader
results in a load loop--require
and --loader
results in a load loop / OOM
@nodejs/loaders |
I'm able to reproduce with the suggested code snippet, but it looks like there's more to it than just combining $ out/Release/node --no-warnings --require ./test/fixtures/printA.js --import ./test/fixtures/printB.js --loader ./test/fixtures/empty.js ./test/fixtures/printC.js
A
A
B
C It looks like the reported bug only happens on REPL. Worth noting that we also another bug that makes the |
I can also reproduce the issue without the REPL: touch require.cjs
touch loader.mjs
echo "setInterval(() => {}, 1000);" > test.cjs
node --require ./require.cjs --loader ./loader.mjs test.cjs |
I don't think it has much to do with $ out/Release/node --loader ./test/fixtures/empty.js
[…never ending output of experimental warning…] |
--require
and --loader
results in a load loop / OOM
Indeed, I've updated the issue to reflect that 👍
That's expected behaviour in my opinion, once in the main process and once in the Worker for the loaders. |
I can't repro at all (admittedly on macOS ARM, but I don't see how this could be OS-related): At snippettouch loader.mjs
echo "setInterval(() => {}, 1000);" > test.cjs
node --loader ./loader.mjs test.cjs runs endlessly (as expected) and memory stays constant (at 20.2 MB, after start-up), with only 1 experimental warning. I get the same behaviour on v20.0.0-proposal's current HEAD (bb533f7), but with slightly less memory consumption (20.1 MB after start-up). The code that controls whether the warning is emitted is quite simple and handles multiple instances of the module loader: node/lib/internal/modules/esm/loader.js Lines 405 to 420 in b342a1b
( Am I missing something? |
I think this is happening because the loader is going to try to spawn a worker thread from within the worker thread, which is also going to do the same thing, and that's how we end up with Mr Meeseeks situation until the system is out of memory or the process terminates. I'm working on a fix. |
I'd note that some systems like ServiceWorkers / SharedWorkers avoid this
by having a shared cache based upon URL of the entrypoint. That would also
reduce overall burden.
…On Mon, Apr 17, 2023 at 1:33 PM Antoine du Hamel ***@***.***> wrote:
I think this is happening because the loader is going to try to spawn a
worker thread from within the worker thread, which is also going to do the
same thing, and that's how we end up with Mr Meeseeks situation until the
system is out of memory or the process terminates. I'm working on a fix.
—
Reply to this email directly, view it on GitHub
<#47566 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABZJI4ZGXW3P53XYIGMCPDXBWEHBANCNFSM6AAAAAAW66HUD4>
.
You are receiving this because you are on a team that was mentioned.Message
ID: ***@***.***>
|
Experiencing the same. The loader is loaded over and over again as soon as I import specific libraries.
esm-loader.mjs
Works fine with Node v18 |
@aduh95 I tested again and the |
--require
and --loader
results in a load loop / OOM
How so? I am seeing the following in v20.0.0 (release) on x86_64 GNU/Linux, running from CLI and $ touch empty.cjs # (does it / should it matter if we use .js .cjs or .mjs here??)
$ echo "setInterval(() => null, 1000);" > wait.js
$ node --loader ./empty.cjs wait.js
(node:668264) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:668264) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:668264) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:668264) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:668264) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
.... Passing
I mean....I guess the message did say that the feature could change at any time, but I am sure that this kind of change was not on purpose :) |
FWIW I'm also able to reproduce without |
@jacobq Interestingly it depends on the extensions used. # OK
node --loader ./loader.mjs
# KO
node --loader ./loader.cjs
node --loader ./loader.js
node --require ./require.cjs --loader ./loader.mjs |
--require
and --loader
results in a load loop / OOM
The reason is it must invoke the CJS module loader to repro (the default is CJS, so |
Use the default loader as the cascaded loader in the loader worker. Otherwise we spawn loader workers in the loader workers indefinitely. PR-URL: #47620 Fixes: #47566 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
when is this fix will be released ?, we are experiencing the same and we want to go over node 20 to have the improvements in cold imports that I already saw. thanks |
Ditto here! Also curious when this will be released. |
With 20.1.0 on 2023-05-02 per nodejs/Release#855, or in a patch release if one is done before then. |
Use the default loader as the cascaded loader in the loader worker. Otherwise we spawn loader workers in the loader workers indefinitely. PR-URL: #47620 Fixes: #47566 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
FYI 20.1.0 is out and the PR for this issue, #47620, is included in it. |
I tested with node 20.1.0 and the problem still exists without any changes: |
Just in case this is useful to anyone - in my case it actually did fix the issue… But it also revealed another one which I think is related: #47880. |
Thank you. 20.1.0 fixed the issue for us. |
Use the default loader as the cascaded loader in the loader worker. Otherwise we spawn loader workers in the loader workers indefinitely. PR-URL: nodejs#47620 Fixes: nodejs#47566 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Use the default loader as the cascaded loader in the loader worker. Otherwise we spawn loader workers in the loader workers indefinitely. PR-URL: #47620 Backport-PR-URL: #50669 Fixes: #47566 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Use the default loader as the cascaded loader in the loader worker. Otherwise we spawn loader workers in the loader workers indefinitely. PR-URL: nodejs/node#47620 Backport-PR-URL: nodejs/node#50669 Fixes: nodejs/node#47566 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Use the default loader as the cascaded loader in the loader worker. Otherwise we spawn loader workers in the loader workers indefinitely. PR-URL: nodejs/node#47620 Backport-PR-URL: nodejs/node#50669 Fixes: nodejs/node#47566 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Version
v20.0.0-nightly20230414c94be4125b
Platform
Linux server 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
Node.js starts up without loading the provided loader over and over again.
What do you see instead?
Node.js spams the console with the following warning while the memory and CPU usage climbs until it's stopped / OOMs.
Additional information
Possibly relevant #44710
The text was updated successfully, but these errors were encountered: