Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kratoon opened this issue Aug 10, 2020 · 1 comment
Open

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

kratoon opened this issue Aug 10, 2020 · 1 comment

Comments

@kratoon
Copy link

kratoon commented Aug 10, 2020

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
}
@Cactusbone
Copy link

Cactusbone commented Nov 18, 2021

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants