Skip to content

Using node with process.stdin inside spawned shell #18446

@qfox

Description

@qfox
  • Version: v8.4.0
  • Platform: 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
  • Subsystem: net, stream or child_process (?)

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:

Error: write EPIPE
    at _errnoException (util.js:1041:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:858:14)

But when we played with it a little:

Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:352:12)
    at __dirname (/Users/qfox/repos/trendbox-ci/omg.js:11:11)
    at <anonymous>

How to repro:

const { spawn } = require('child_process');
const pause = t => new Promise(resolve => setTimeout(resolve, t));

const { stdin } = spawn('bash', [/*'-i'*/], { stdio: ['pipe', 'inherit'] });

(async () => {
    stdin.write('echo All is fine here\n');
    await pause(200);
    stdin.write('node -e process.stdin && echo After process.stdin\n');
    await pause(2000); // It's important: the bigger pause, the more frequently occurs
    stdin.write('echo After all\n');
})().catch(e => console.error(e.stack));

If we remove usage of process.stdin or force shell to be interactive (pass in ['-i'] flag) or just call node -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

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions