Inside my worker file I listen for a data callback. someLib
is node-serialport.
process.on('message', function(msg) {
someLib.on('data', function(data){
console.log('some data');
process.send(data);
});
});
This prints
some data
Error: channel closed
But
process.on('message', function(msg) {
process.send('foobar');
});
works fine. It is strange but sometimes the first code example works, so the channel closed error appears randomly.
From http://nodejs.org/api/child_process.html#child_process_event_error I get the info that the error is triggered when
Sending a message to the child process failed for whatever reason.
What is "whatever reason"? Any ideas?
spawn returns an object with stdout and stderr streams. You can tap on the stdout stream to read data that the child process sends back to Node. stdout being a stream has the "data", "end", and other events that streams have.
if you want to relaunch app again then you should just close or hide all windows and activate setInterval to keep checking if child process is alive or not with help of pid ... after that you can create new window again or show hidden window... and if you want fresh process then you should relaunch app after you get ...
spawnSync() function provides equivalent functionality in a synchronous manner that blocks the event loop until the spawned process either exits or is terminated. For convenience, the node:child_process module provides a handful of synchronous and asynchronous alternatives to child_process. spawn() and child_process.
The problem was that forked child processes were not closed correctly when parent was killed. This resulted in multiple ghost processes that caused the channel closed error.
I hooked into the SIGHUP and killed them gracefully. Now everything works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With