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

child_process: null channel handle on close #3041

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
1 change: 1 addition & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
@@ -449,6 +449,7 @@ function setupChannel(target, channel) {
target.disconnect();
channel.onread = nop;
channel.close();
target._channel = null;
maybeClose(target);
}
};
40 changes: 40 additions & 0 deletions test/parallel/test-child-process-fork-regr-gh-2847.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const common = require('../common');
Copy link
Contributor

Choose a reason for hiding this comment

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

common should be loaded first. It has some global pollution detection logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok.

const assert = require('assert');

const cluster = require('cluster');
const net = require('net');
const util = require('util');

if (!cluster.isMaster) {
// Exit on first received handle to leave the queue non-empty in master
process.on('message', function() {
process.exit(1);
});
return;
}

var server = net.createServer(function(s) {
setTimeout(function() {
s.destroy();
}, 100);
}).listen(common.PORT, function() {
var worker = cluster.fork();

function send(callback) {
var s = net.connect(common.PORT, function() {
worker.send({}, s, callback);
});
}

worker.process.once('close', common.mustCall(function() {
// Otherwise the crash on `_channel.fd` access may happen
assert(worker.process._channel === null);
server.close();
}));

// Queue up several handles, to make `process.disconnect()` wait
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the surrounding code, without this loop also the assertion in close event will be satisfied, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

The worker won't exit without the loop. It expect the message to come. Sending multiple items is crucial to make this test fail on the unpatched node.

for (var i = 0; i < 100; i++)
send();
});