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

add test and docs update for detached fork process #24524

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/child_process.md
Expand Up @@ -325,6 +325,9 @@ changes:
* `args` {string[]} List of string arguments.
* `options` {Object}
* `cwd` {string} Current working directory of the child process.
* `detached` {boolean} Prepare child to run independently of its parent
process. Specific behavior depends on the platform, see
[`options.detached`][]).
* `env` {Object} Environment key-value pairs.
* `execPath` {string} Executable used to create the child process.
* `execArgv` {string[]} List of string arguments passed to the executable.
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/parent-process-nonpersistent-fork.js
@@ -0,0 +1,12 @@
const fork = require('child_process').fork;
const path = require('path');

const child = fork(
path.join(__dirname, 'child-process-persistent.js'),
[],
{ detached: true, stdio: 'ignore' }
);

console.log(child.pid);

child.unref();
23 changes: 23 additions & 0 deletions test/parallel/test-child-process-fork-detached.js
@@ -0,0 +1,23 @@
'use strict';
require('../common');
const assert = require('assert');
const fork = require('child_process').fork;
const fixtures = require('../common/fixtures');

const nonPersistentNode = fork(
fixtures.path('parent-process-nonpersistent-fork.js'),
[],
{ silent: true });

let childId = -1;

nonPersistentNode.stdout.on('data', (data) => {
childId = parseInt(data, 10);
nonPersistentNode.kill();
});

process.on('exit', () => {
assert.notStrictEqual(childId, -1);
// Killing the child process should not throw an error
process.kill(childId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This strikes me as having significant potential for leaving stray processes around on CI. Not necessarily blocking, but surely something to keep an eye on after this lands....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I totally agree. One of my checks was to make sure that no node processes were running after I ran the test individually.

});