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
{{ message }}
Repository navigation
Lost input from child processes due to initially-flowing net.Socket. #5034
When opening child processes with child_process.spawn using 'pipe' for its stdout or stderr, the resulting stream is already in the flowing state when it's returned, and some data can be lost when consuming the stream using the 'readable' event + read(). A minimal example:
On recent node versions, no data is read; the 'readable' event only fires once, for end-of-stream. On older versions, the first chunk of data is read. I'm not sure which exact version introduced the bug, but:
Activity
awpr commentedon Feb 2, 2016
Also relevant, replacing the 'echo' with a read of a named pipe shows different behavior based on how quickly input becomes available on the pipe:
const spawn = require('child_process').spawn;
const ls = spawn('cat', ['/tmp/the_named_fifo']);
% cat /tmp/test.js
console.log("flowing:", ls.stdout._readableState.flowing);
ls.stdout.on('readable', function() {
console.log("read:", ls.stdout.read());
});
% mkfifo /tmp/the_named_fifo
% node --version && node /tmp/test.js & echo hi >> /tmp/the_named_fifo; wait
v5.1.0
[1] 13721
flowing: null
read: null
[1] + done node /tmp/test.js
% node --version && node /tmp/test.js & sleep 1; echo hi >> /tmp/the_named_fifo; wait
v5.1.0
[1] 13730
flowing: null
read: <Buffer 68 69 0a>
read: null
[1] + done node /tmp/test.js
mscdex commentedon Feb 2, 2016
I think I have a fix for this coming up ...
mscdex commentedon Feb 2, 2016
#5036 should fix this
child_process: fix data loss with readable event
child_process: fix data loss with readable event
child_process: fix data loss with readable event
child_process: fix data loss with readable event
child_process: fix data loss with readable event
child_process: fix data loss with readable event
child_process: fix data loss with readable event
child_process: fix data loss with readable event
child_process: fix data loss with readable event