You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IPC with a ES6 child process created via child_process.fork() appears to go nowhere. When sending a message, the child appears to never receive it. Further testing shows that other events (eg exit) are working.
To demonstrate, parent.mjs:
importcpfrom'child_process';constkid=cp.fork('test.mjs');kid.send({msg: "Hey there kid"});setTimeout(()=>{process.exit(0)},2000);
To test further, I created my own named socket IPC using net.createServer(path), between such a parent and child, and bidirectional communication is working.
I really just want to know if this is something I should create an issue about.
Can you try putting the .send in a setTimeout? I think you're calling .send synchronously before the child process has run the process.on( 'message', (m) => { test.msg(m) } ); code.
in general you can see dropped messages due to timing like @benjamingr said, it is a much more foolproof workflow to have your child notify the parent that it is fully loaded before sending it messages from the parent.
Activity
vsemozhetbyt commentedon Jul 12, 2018
cc @nodejs/child_process @nodejs/modules-active-members
benjamingr commentedon Jul 12, 2018
Can you try putting the
.sendin asetTimeout? I think you're calling.sendsynchronously before the child process has run theprocess.on( 'message', (m) => { test.msg(m) } );code.bmeck commentedon Jul 12, 2018
in general you can see dropped messages due to timing like @benjamingr said, it is a much more foolproof workflow to have your child notify the parent that it is fully loaded before sending it messages from the parent.
sammyrc34 commentedon Jul 12, 2018
@benjamingr Thank you! You're correct.
@bmeck, yes, that is a much better approach.
Thank you both for the help.