Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
child_process: tracking unrefdness of child_process
- initializing `_unref` to `false` when child process is created
- updating that value each time either `unref()` or `ref()` is invoked
- this mirrors the implementation in `lib/net.js`
- adding test to check unrefdness tracking
  • Loading branch information
thlorenz committed Mar 21, 2016
commit debe1811e89a0617fc446c885cb03e4af127e16a
3 changes: 3 additions & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function ChildProcess() {

this._handle = new Process();
this._handle.owner = this;
this._unref = false;

this._handle.onexit = function(exitCode, signalCode) {
//
Expand Down Expand Up @@ -388,11 +389,13 @@ ChildProcess.prototype.kill = function(sig) {


ChildProcess.prototype.ref = function() {
this._unref = false;
if (this._handle) this._handle.ref();
};


ChildProcess.prototype.unref = function() {
this._unref = true;
if (this._handle) this._handle.unref();
};

Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-child-process-ref-unref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
const spawn = require('child_process').spawn;
const cmd = common.isWindows ? 'rundll32' : 'ls';
const assert = require('assert');

const cp = spawn(cmd);
assert.ok(cp.hasOwnProperty('_unref'));
assert.ok(!cp._unref);
cp.unref();
assert.ok(cp._unref);
cp.ref();
assert.ok(!cp._unref);
cp.unref();
assert.ok(cp._unref);