Nw.js: Spawned child process fails due to stdout & stderr filling up with no way to read from parent

Created on 17 Jan 2018  路  8Comments  路  Source: nwjs/nw.js

Please post a workaround if one is known. Thanks!

NWJS Version : 0.27.4
Node Version : 9.3.0
Operating System : Windows 7

Expected behavior

Message traffic between parent and spawned child should continue uninterrupted

Verified expected behavior with - NWJS Version : 0.19.4, Node Version : 7.2.0

Actual behavior

The spawned child process exits with error code: 3221225477

Sub problems:

  • maxBuffer config parameter does not appear to change the buffer size for spawn or fork
  • Unable to consume stdout or stderr on the parent side
  • The more that spawned processes that leverage third party products that print to stdout, the faster the error occurs

How to reproduce

Run the following code with a helloWorld.html of your choice.

package.json

{ "name": "scratch", "version": "0.0.1", "main": "index.js" }

index.js

`
const path = require('path');
const gui = require('nw.gui');
const spawn = require('child_process').spawn;

gui.Window.open('helloWorld.html', {}, function(win) {});

//Create spawned process
var child = spawn(process.execPath, ['./child.js'], {
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
execPath: process.execPath
});

//Message sent back from child
child.on('message', function(m) {
console.log('[Child message] ' + m.msg);
});

//Continually send messages to child (simulates typical IPC traffic)
setInterval(function() {
console.log('ping')
child.send('ping');
}, 50);

process.on('uncaughtException', function (err) {
console.error(err);
});
`

child.js

`
//Respond to pings with pongs
process.on('message', function(m) {
setTimeout(function() {
//Add a little bit of print litter to stdout to speed up the errors

process.stdout.write('stdout111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111');
process.send({msg: 'pong'});
});
});
`

P2 bug regression test-todo triaged

Most helpful comment

This is fixed in git and will be available in the next nightly build.

All 8 comments

I tried it on Windows 8.1 with nwjs-sdk-v0.27.4, child process stopped and an error occurred:
image

This doesn't happen on Linux with nwjs-sdk-v0.27.4.

I am running into the same issue in an application with multiple spawned processes. The application is currently unusable with the same upgrade as the OP. I'm also on Windows 7 as well.

Not sure if this is related, but I'm using the fork command to spawn a nodejs process and it seems to die immediately on Windows 10 using NW.js 0.27.5.

The only error that prints out is events.js:136 Uncaught NodeError: Channel closed when I try to send a message to the process.

When running with NW.js 0.26.6 it works fine.

Yeah this seems to be a regression in 0.27

This is fixed in git and will be available in the next nightly build.

Thanks, that 28.1 build appears to be working in my case.

That worked for my original issue. Thank you for addressing it so quickly.

Was this page helpful?
0 / 5 - 0 ratings