Skip to content

EBADF: bad file descriptor, uv_pipe_open on windows with ipc #137

Open

Description

@kratoon

Stack trace:

Hey guys, I have a problem with child_process on windows while using ipc so I asked a question.

I found this module to solve it but the same error happens.

The problem occurs on windows, spawning something in js (e.g. npm or child.js) and with ipc option.
The ipc is required as some of the commands will be my commands and I need to communicate with it.

I am not sure what I am doing wrong. Thanks for help.

Code:

const spawn = require('cross-spawn');
const cmd = spawn('npm', ['-v'], {shell: true, stdio: ['inherit', 'inherit', 'inherit', 'ipc'] } ));

cmd.on('message', (msg) => console.log({msg}));
cmd.on('close', (code) => console.log({code}));

Stack trace:

child_process.js:122
  p.open(fd);
    ^

Error: EBADF: bad file descriptor, uv_pipe_open
    at Object._forkChild (child_process.js:122:5)
    at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:329:30)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:54:3)
    at internal/main/run_main_module.js:7:1 {
  errno: -4083,
  code: 'EBADF',
  syscall: 'uv_pipe_open'
}
child_process.js:122
  p.open(fd);
    ^

Error: EBADF: bad file descriptor, uv_pipe_open
←[90m    at Object._forkChild (child_process.js:122:5)←[39m
←[90m    at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:329
:30)←[39m
←[90m    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:54:3
)←[39m
←[90m    at internal/main/run_main_module.js:7:1←[39m {
  errno: ←[33m-4083←[39m,
  code: ←[32m'EBADF'←[39m,
  syscall: ←[32m'uv_pipe_open'←[39m
}

Activity

  1. Cactusbone commented on Nov 18, 2021

    @Cactusbone

    I have the same error using

    serverProcess = crossSpawn('node', [
                someScriptFullPath,
                '--port', serverPort,
            ], {
                stdio: [null, null, null, 'ipc'],
            });

    on node 16, with nodist

    I believe (in my case), that nodist is the culprit because the shim is in go, and docs says

    Accessing the IPC channel fd in any way other than process.send() or using the IPC channel with a child process that is not a Node.js instance is not supported.

    so it probably breaks here.

    a workaround is to use fork which does not use the shim

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions