-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Loaders that use childProcess.fork lead to endless recursion of processes #47615
Comments
Oh also, if such a solution were to be used, for chained loaders this only needs to be the last loader in the current chain that is removed. i.e. If we have |
This seems to me firmly a case of "just don't do that." |
Third party libraries, like |
Then you should work with the typescript people to resolve that. I don't think it's node's job to protect against fork bombs. |
Running your I tried adding This is like the error I came to the issues to find. This is only Given that I can do |
Well in this case I don't think the behaviour even makes sense, the threaded implementation of loaders still has // loader.mjs
// ["--loader", "./loader.mjs"]
console.log(process.execArgv); This means forked processes receive this by default in their But this doesn't make sense, the loader thread isn't loaded using |
That's changing the subject / moving the goal posts, isn't it? Your original bug report is about |
Well the problem comes from the fact that Ultimately I don't really care about what solutions are applied, but the fact that existing libraries are broken within a loader compared to previously is to me the problem here. The reason I think changing |
@nodejs/loaders |
Could this be a duplicate of #47566? |
I can confirm it's not a duplicate of #47566, #47615 (comment) seems to be correct. I agree that not supporting this use case is tempting, but not very manageable indeed. FWIW, as a workaround, you might be interested in sucrase as an alternative for transpile TS to JS that doesn't use forks. |
I imagine that the problem would also happen if the loaders are set by |
So the obvious solution seems to be to eliminate loader info from |
@GeoffreyBooth there is no problem to communicate with another loader in complex setup - nextResolve / nextLoad can be used as bi-directional channel (as an example, esmock client detects loader via this way, not by argv / NODE_OPTIONS parsing). |
Just to be clear the suggestion I am making here is that the active loader is removed from the list. So if we have the command
Essentially from the perspective of each loader thread, their Put another way, from the perspective of each thread here the list of loaders is simply the loaders the apply to the current thread. |
I think that assumes that the |
Are all loaders in one thread? How does this work if |
Loaders are loaded serially in the loader thread, so when |
Version
v20.0.0
Platform
Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
loaders
What steps will reproduce the bug?
Use
childProcess.fork
within a loader, for example in the following loader:And run
node --loader ./loader.mjs ./test.mjs
.How often does it reproduce? Is there a required condition?
This happens consistently.
What is the expected behavior? Why is that the expected behavior?
The short answer is I'm not sure what should be done here. But it seems problematic that libraries (such as
typescript
) that useschildProcess.fork
cannot be used within a loader without endless recursion of processes.Perhaps the solution is simply not to carry over loaders onto child processes that are forked within loaders.
What do you see instead?
Loaders get continually created spamming the console with:
while also rapidly growing memory usage from the endless chain of processes.
Additional information
I noticed this because
ts-node
rapidly memory leaks in Node 20. I experimented it a bit and found that TypeScript is callingchildProcess.fork
which causes this error. i.e. A minimal loader that exhibits this behaviour would just be:Using this loader with
node --loader ./loader.mjs ./test.mjs
will rapidly consume all memory on the machine until the OS kills the process (if not terminated sooner).The text was updated successfully, but these errors were encountered: