Skip to content

Accessing process.stdin hangs on Windows #10836

Description

@segrey

Let's consider this example project consisting of 3 files:

// main.js
var spawn = require('child_process').spawn;
var middle = spawn(process.execPath, ['middle.js'], {
    'stdio': 'pipe'
});

middle.stdout.on('data', function(data) {
    process.stdout.write('stdout from middle: ' + data);
});

middle.stderr.on('data', function(data) {
    process.stdout.write('stderr from middle: ' + data);
});

middle.on('close', function(code) {
    process.stdout.write('middle process finished with exit code ' + code);
});
// middle.js
var spawn = require('child_process').spawn;
var stdin = process.stdin;
console.log('middle: isatty(stdin)=' +require('tty').isatty(stdin));
spawn(process.execPath, ['child.js'], {
    'stdio': [process.stdin, process.stdout, process.stderr]
});
// child.js
console.log('child: accessing process.stdin');
console.log('child: done successfully ' + process.stdin);

Running node main.js in cmd.exe should normally output these lines and exit

stdout from middle: middle: isatty(stdin)=false
stdout from middle: child: accessing process.stdin
stdout from middle: child: done successfully [object Object]
middle process finished with exit code 0

However, from time to time it outputs only two first lines and hangs:

stdout from middle: middle: isatty(stdin)=false
stdout from middle: child: accessing process.stdin

The hanging is caused by accessing process.stdin in child.js. Please note it works fine if process.stdin is replaced with 'pipe' here:

// middle.js
...
spawn(process.execPath, ['child.js'], {
    'stdio': ['pipe', process.stdout, process.stderr]
});

Node.js v7.4.0
OS Windows 10

Activity

  1. added
    child_processIssues and PRs related to the child_process subsystem.
    windowsIssues and PRs related to the Windows platform.
    on Jan 16, 2017
  2. addaleax commented on Jan 16, 2017

    @addaleax
    Member

    /cc @nodejs/platform-windows

  3. seishun commented on Jan 16, 2017

    @seishun
    Contributor

    See also #5620

  4. Fishrock123 commented on Jan 16, 2017

    @Fishrock123
    Contributor

    Does changing the spawn option to 'inherit' for stdin make any difference?

  5. segrey commented on Jan 16, 2017

    @segrey
    Author

    @Fishrock123 If you meant changing middle.js, like

    // middle.js
    ...
    spawn(process.execPath, ['child.js'], {
        'stdio': 'inherit'
    });

    Then, no, it doesn't make any difference for me.
    As for changing main.js, it's will change the behavior, yes. However, middle.js is executed with piped standard streams (not tty) in my environment, so it's impossible to make this change for me.

  6. Fishrock123 commented on Jan 16, 2017

    @Fishrock123
    Contributor

    If you meant changing middle.js, like

    Correct. Just making sure there wasn't any hidden Windows logic in inherit.

  7. Trott commented on Jul 15, 2017

    @Trott
    Member

    @bzoz Is fixing this likely blocked by until libuv/libuv#1273 or equivalent lands in libuv and the appropriate version of libuv gets upstreamed to our deps directory?

  8. bzoz commented on Jul 17, 2017

    @bzoz
    Contributor

    Yes

  9. 6 remaining items

  10. added a commit that references this issue on Feb 12, 2018
  11. added a commit that references this issue on Feb 17, 2018
  12. added a commit that references this issue on Feb 21, 2018
  13. added a commit that references this issue on Feb 22, 2018
  14. added a commit that references this issue on Feb 26, 2018
  15. added a commit that references this issue on May 8, 2018
  16. added a commit that references this issue on Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions