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

Output of forked process not piped to debugger #24295

Closed
VentyCZ opened this issue Nov 10, 2018 · 4 comments
Closed

Output of forked process not piped to debugger #24295

VentyCZ opened this issue Nov 10, 2018 · 4 comments
Labels
child_process Issues and PRs related to the child_process subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. inspector Issues and PRs related to the V8 inspector protocol

Comments

@VentyCZ
Copy link

VentyCZ commented Nov 10, 2018

  • Version: v10.13.0 (also present on v8.11.3)
  • Platform: Windows 10 (64bit) (Also tested on Debian 9)

When using --inspect(-brk), the output of the child_process.forked script is not sent to the attached debugger.

I tried multiple options of stdio for child_process.fork function, all to no avail.

Test case

index.js

// Warning: if ran with --inspect(-brk) option, the wroker output (stdio) is NOT piped to the debugger
require('child_process').fork(`${__dirname}/worker.js`, [], {
    // Filter out the inspector/debugger options, so the debugger works properly
    execArgv: process.execArgv.filter((arg) => !arg.startsWith('--inspect'))
});

setInterval(() => {
    // This is going to be printed out to the debugger!
    console.log('Main script message!');
}, 1000);

worker.js

setInterval(() => {
    // This is NOT going to be printed out to the debugger!
    console.log('Worker message!');
}, 1000);

Test case result

All you can see in the Chrome DevTools Console is 'Main script message' written every second, but not the message from the worker (forked process). But all the output is written to the process stdout (after running node --inspect-brk index.js).

Expected result

The output written to the debugger should be the same as the stdout.

@VentyCZ
Copy link
Author

VentyCZ commented Nov 10, 2018

Is it possible to pass the child process output to the already attached debugger, or should I use a separate debugger for the child process (I just need to see the log output) ?

@VentyCZ
Copy link
Author

VentyCZ commented Nov 10, 2018

As of now, the current workaround is as follows (IPC communication still works after the stdio option changes):

index.js

// Warning: if ran with --inspect(-brk) option, the wroker output (stdio) is NOT piped to the debugger
// https://github.com/nodejs/node/issues/24295
let wk = require('child_process').fork(`${__dirname}/worker.js`, [], {
    // Filter out the inspector/debugger options, so the debugger works properly
    execArgv: process.execArgv.filter((arg) => !arg.startsWith('--inspect')),
    stdio: 'pipe'
});

wk.stdout && wk.stdout.on('data', (data) => {
    console.log(data.toString().trim());
});

wk.stderr && wk.stderr.on('data', (data) => {
    console.error(data.toString().trim());
});

@targos targos added child_process Issues and PRs related to the child_process subsystem. inspector Issues and PRs related to the V8 inspector protocol labels Nov 11, 2018
@targos
Copy link
Member

targos commented Nov 11, 2018

I think that is not possible without your workaround (or using the experimental Worker Threads API).

@bnoordhuis
Copy link
Member

Duplicate of #9435, which is still unresolved as of this writing. See the discussion in that issue, it's basically around the pros and cons of the workaround you posted.

@bnoordhuis bnoordhuis added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

No branches or pull requests

3 participants