Skip to content

spawn's stdio can result in stderr being closed in child #862

Description

@sam-github
var cp = require('child_process');
var fs = require('fs');

if (process.env.CHILD) {
  console.error('ERROR');
  return;
}
// open child stdout and stderr on our stderr
var options = {
  stdio: [0, 2, 2],
  env: { CHILD: true },
};
var c = cp.spawn(process.execPath, [__filename], options);

Result: 'ERROR' is not printed.

Excerpt from strace:

[pid 11780] write(2, "ERROR\n", 6)      = -1 EBADF (Bad file descriptor)
[pid 11780] write(2, "ERROR\n", 6)      = -1 EBADF (Bad file descriptor)
[pid 11780] epoll_ctl(4, EPOLL_CTL_DEL, 2, {EPOLLWRNORM|EPOLLHUP|EPOLLRDHUP|EPOLLET|0x242e0000, {u32=32767, u64=47321597480042495}}) = -1 ENOENT (No such file or directory)
[pid 11780] write(2, "events.js:141\n      throw er; //"..., 244) = -1 EBADF (Bad file descriptor)
[pid 11780] exit_group(1)               = ?
[pid 11785] +++ exited with 1 +++

This likely a bug in libuv, but reporting it here because that's where I saw it.

Affects node v0.10 and io.js.

/cc @saghul @bnoordhuis I think we tried to fix a variant of this a year or so ago.

Activity

  1. saghul commented on Feb 17, 2015

    @saghul
    Member

    I believe that's still not fixed. This is the closest open issue I could find: joyent/libuv#923

  2. bnoordhuis commented on Feb 17, 2015

    @bnoordhuis
    Member

    I think this asks for a two-pronged approach: libuv probably has a bug or two that need to be addressed but io.js could reopen fds 0-2 as /dev/null if they aren't valid file descriptors.

  3. vkurchatkin commented on Feb 17, 2015

    @vkurchatkin
    Contributor

    @bnoordhuis can you also comment on #831 ?

  4. sam-github commented on Feb 18, 2015

    @sam-github
    ContributorAuthor

    Opening fd 2 on /dev/null would avoid the EBADF, and probably is a good idea, so fd 2 doesn't become some random open file, but wouldn't avoid the underlying problem, that console.error() never prints, because stderr is gone.

    I dug up the last time I saw this:

  5. sam-github commented on Feb 24, 2015

    @sam-github
    ContributorAuthor

    @saghul I think I've fixed this, as well as some related bugs. I'm putting together some node tests, then I'll PR the fix to libuv.

  6. saghul commented on Feb 24, 2015

    @saghul
    Member

    Great! Thanks Sam.
    On Feb 24, 2015 6:57 PM, "Sam Roberts" notifications@github.com wrote:

    @saghul https://github.com/saghul I think I've fixed this, as well as
    some related bugs. I'm putting together some node tests, then I'll PR the
    fix to libuv.

    —
    Reply to this email directly or view it on GitHub
    #862 (comment).

  7. added a commit that references this issue on May 6, 2015
  8. bnoordhuis commented on May 6, 2015

    @bnoordhuis
    Member

    Should be fixed by 04cc03b. Closing, holler if I should reopen it.

  9. added a commit that references this issue on May 19, 2015
  10. leth commented on Sep 7, 2016

    @leth

    I'm seeing a failure like this frequently from npm install under node 6.4.0.

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

    confirmed-bugIssues and PRs for confirmed bugs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions