-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
Piping process.stdin
to child.stdin
leaves behind an open handle
#415
Comments
Hi @jsumners, Thanks for reaching out. This is intended behavior. If you run the above script in a terminal and type a line of input then "Enter", |
Yes, that's my point. |
I could not reproduce this. I am using the latest version of Execa ( |
I think I found the issue: If you pass the |
Here's the catch: I'm seeing this behavior when wrapping |
I believe |
Can we get past Create a simple echo utility: foo.c: #include <stdio.h>
int main() {
char str[100];
gets(str);
puts(str);
return 0;
} Compile it: Update the provided example: index.js: 'use strict'
const execa = require('execa')
const wtfnode = require('wtfnode')
main()
.then(() => {
console.log('!!! done')
wtfnode.dump()
})
.catch(console.error)
async function main () {
console.log('write something and press "enter"')
const child = execa('./foo')
process.stdin.pipe(child.stdin)
await child
process.stdin.unpipe(child.stdin)
} Run |
This version of the script works as expected: 'use strict'
const execa = require('execa')
const wtfnode = require('wtfnode')
main()
.then(() => {
console.log('!!! done')
wtfnode.dump()
})
.catch(console.error)
async function main () {
console.log('write something and press "enter"')
await execa('./foo', [], { stdio: 'inherit' })
} |
This bug can be reduced to the following script: const execa = require('execa')
const child = execa('./foo')
process.stdin.pipe(child.stdin)
child.then(() => {
console.log('done')
process.stdin.unpipe(child.stdin)
}) The entered line is correctly read on Now it turns out this seems to be an issue with Node.js itself, not with Execa. You can reproduce it with: const { spawn } = require('child_process')
const child = spawn('./foo')
process.stdin.pipe(child.stdin)
child.on('exit', () => {
console.log('done')
process.stdin.unpipe(child.stdin)
}) I opened nodejs/node#32291 to track this bug in Node.js. I will close this issue since this is not caused by Execa itself. |
Run that script and watch the process hang because there is an open handle in the event loop. Thus far, my only solution is to add a
process.stdin.unref()
.The text was updated successfully, but these errors were encountered: