Skip to content

discussion about how to fix child_process 'spawn' not ready to send messages on ESM #41134

Description

@ErickWendel

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions