-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using pipes other than stdin, stdout, stderr for streaming data into a child process, ENOTCONN error is thrown #13542
Comments
I met the same issue, after a bit investigation it seems a legacy child process bug on handling any FD >= 3: |
Haven't tested with imagemagick, however the following works on CentOS 7: fd-writer.c #include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
if (argc == 1) {
printf("Usage: %s fd1 [fd2] ...\n", argv[0]);
return 1;
}
char* text = "Hello\n";
int fd = 1, i = 1;
while (i < argc && (fd = atoi(argv[i++]))) {
if (!fd) continue;
write(fd, text, strlen(text) + 1);
close(fd);
}
return 0;
} $ gcc ./fd-writer.c -o ./fd-writer fd-writer will write "Hello" to each file descriptor passed in. test.js const { spawn } = require('child_process');
const child = spawn('./fd-writer', [3], {
stdio: [null, null, null, 'pipe']
});
child.stdio[3].on('data', chunk => {
process.stdout.write(chunk);
}); $ node test.js So definitely not an issue with fd >= 3. Have you tried writing directly to the stream? e.g.
|
@noahnu Hi, yes, I've tried that. Writing the data seems fine, however, on closing the input stream (which tells the spawned process that no more data is coming in) I get a similar error. The subprocess I called in this example is imagemagick which supports inputs with fds >= 3, I've tested that aswell. |
I'm experiencing this as well, under OS X. |
the same error here, node version 8.7, linux |
We can confirm this error under Linux (Debian):
We used |
Version:
tested with 7.5 and 8.0
Platform:
OSX Sierra; Darwin Kernel Version 16.3.0 root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64
Example code:
brew install imagemagick
Details:
I am trying to pipe a stream, which i got from request, to the command line in order to manipulate the received data. When i am sending the data to stdin of the child process, everything works fine. In my example, you can see that result by running the commented code rather than the uncommented.
If I pipe the stream to a pipe other than stdin, stdout or stderr, which should be possible according to the docs I get the following exception:
I tried multiple things, for example passing in the stream object directly when specifying the stdio object (which should be possible too according to the linked doc entry) but then I get a type error, even though I am clearly passing in a stream. I cant see the difference between the two examples I provided and am rather puzzled by the different result.
Thanks for looking into this!
The text was updated successfully, but these errors were encountered: