Reputation: 730
Executing child_process.fork
from a vscode debug process fails to run with and returns exit code 12. Running the same test from a terminal session succeeds.
import { expect } from 'chai';
import { fork } from 'child_process';
import path from 'path';
describe('Child Process Fork', () => {
it('Successfully Forks A Simple Process', (done) => {
const child = fork(path.join(__dirname, 'SimplyExit.js'), [], { stdio: 'pipe' });
child.on('exit', (data) => {
expect(data).to.equal(0);
done();
});
});
});
process.exit(0);
Upvotes: 2
Views: 2478
Reputation: 730
Executing child_process.fork
from a parent node process that was started with an inspect-brk
option active will cause this error if you don't manually specify a different inspect-brk
port or remove the option.
Here's the line of code in the node.js source that causes this to happen
Add execArgv: []
to your fork options to prevent the child process from inheriting the inspect-brk
option. Here's the full working code.
import { expect } from 'chai';
import { fork } from 'child_process';
import path from 'path';
describe('Child Process Fork', () => {
it('Successfully Forks A Simple Process', (done) => {
const child = fork(path.join(__dirname, 'SimplyExit.js'), [], { stdio: 'pipe', execArgv: [] });
child.on('exit', (data) => {
expect(data).to.equal(0);
done();
});
});
});
Upvotes: 5