Skip to content

Piping process.stdin to child.stdin leaves behind an open handle #32291

Open
@ehmicky

Description

@ehmicky
  • Version: 13.11.0 (tried on 8.3.0 too, same result)
  • Platform: Linux
  • Subsystem: Ubuntu 19.10

What steps will reproduce the bug?

foo.c

#include <stdio.h>
int main() {
  char str[100];
  gets(str);
  puts(str);
  return 0;
}

Compile it:

$ gcc -o foo foo.c

index.js:

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)
})

Launch index.js:

$ node index.js
input
done

After entering some input, the child process exits and done is printed. However the main process does not exit (although it should). It looks like process.stdin has a left handle. After entering newline again on stdin, the process now exits.

How often does it reproduce?

Always

What is the expected behavior?

See above.

What do you see instead?

See above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions