-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Using node with process.stdin inside spawned shell #18446
Comments
consistently recreatable in Linux, with this code: var child = require('child_process').spawn('bash')
child.stdin.write('node -e process.stdin\n')
setTimeout(() => {
child.stdin.write('echo hello world!\n')
},1000) strace shows that while trying to read the second command, after the sleep. EAGAIN for read manual says: So looks like bash is handing over its fd 0 (a socket in this case) it got from node as it is to the child node.
so Node makes it non-blocking to fit its use case
back in bash, it waits to read from fd 0, but the Unfortunately With this understanding, it is easy to recreate without Node in the picture: #cat 18446.cc #include <sys/ioctl.h>
int main() {
int set = 1;
ioctl(0, FIONBIO, &set);
return 0;
} #g++ 18446.cc Should we restore the standard streams on exit? I thought I have seen a PR on this line. /cc @bnoordhuis |
This issue has been resolved via #20592 and I have verified with both the test programs. #node 18446.js
Closing this, fix will mostly be available in the next current release. |
Thank you very much! |
unfortunately #20592 was reverted in master, so re-opening this. |
This should have been fixed by #24260 so I'll go ahead and close it out. |
v8.4.0
Darwin duplo 15.6.0 Darwin Kernel Version 15.6.0: Tue Apr 11 16:00:51 PDT 2017; root:xnu-3248.60.11.5.3~1/RELEASE_X86_64 x86_64
Tested with:
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)
Not sure is this the same or another bug but in my environment it throws:
But when we played with it a little:
How to repro:
If we remove usage of
process.stdin
or force shell to be interactive (pass in['-i']
flag) or just callnode -e process.stdin
with</dev/stdin
— then the problem disappears.Would be nice to have a good error message if it's unfixable ;'-(
upd:
See also: #947, #2339, #13278
The text was updated successfully, but these errors were encountered: