-
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
discussion about how to fix child_process 'spawn' not ready to send messages on ESM #41134
Comments
Seems like a fine idea to me but would want to hear what @nodejs/modules and/or @nodejs/child_process folks might have to say about it. |
I'd prefer if we could queue things because this problem isn't unique to ESM and I've seen it in the long past using purely CJS and callbacks. |
I think I didn't get it. What do you mean by queue things? |
I don't get it too... do you can explain please? |
@gabrielsimas MessagePort will queue messages (events) and wait for a listener before draining the messages. The problem in this issue is that event listeners which are used in |
This was my first thought |
niiice! It's the same strategy @addaleax suggested on the post, right? |
You have a reproduction of the behavior @ErickWendel? |
Or the behavior is the same on the related content you shared? |
Yes, Actually they already had reproduced the behavior at all of the issues I mentioned in the post. See this one #39140 |
This is the way to go |
It fixes the problem for child process not receiving messages when forking a process and immediately sending messages on ESM by queuing messages until the process is ready. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
It fixes the problem for the child process not receiving messages. Fixes: nodejs#41134
For future searchers: This has been resolved and released in v17.4.0. (🎉) |
It fixes the problem of the child process not receiving messages. Fixes: nodejs#41134 PR-URL: nodejs#41221 Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Also released in 16.14.0 if you're on LTS. |
It fixes the problem of the child process not receiving messages. Fixes: nodejs#41134
* chore: update yarn=4.0.0-rc.2 typescript=4.6.3 * fix(webmonetization-wext): alias Document['visibilityState'] * feat(ci): run yarn dlx @yarnpkg/sdks vscode * chore: log the node version * fix: set jest maxWorkers=1 to workaround nodejs/node#41134 * fix: properly pass args after -- * fix: run yarn dedupe * fix: better method of configuring 1 jest worker * fix: jest validates config, must be number or string * feat: use node 18 and 16 LTS * feat: use cimg/* * feat: use specific version * feat: remove maxWorkers workaround
BTW: I'd like to help fixing this bug 🤩
Is your feature request related to a problem? Please describe.
There's a current issue on spawn's child processes using ES modules mentioned in those issues (#37782, #39140, #39140, #34785, and help/issues/1383 ).
When you fork a file and immediately use the
.send
event. The child process doesn't receive messages because it's not ready yet.So we need to make a workaround. The child emits an event, the parent waits for
.on('message',
we check the message and then we start sending messages to the child.Describe the solution you'd like
My plan initially was to add an event like
child.on("ready
to specify when we can start sending messages to the child process.I spoke to @addaleax and she suggested a behavior that is closer to what
MessagePorts
expose, which is queueing up messages until a message listener is installed.I know that it would increase implementation complexity a bit, but it would be very helpful for avoiding pitfalls like the ones linked here
What do you think? Any ideas of what could we do?
The text was updated successfully, but these errors were encountered: