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

cluster: add handle ref/unref stubs in rr mode #2274

Merged
merged 1 commit into from
Jul 30, 2015
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,22 @@ function workerInit() {
return 0;
}

// XXX(bnoordhuis) Probably no point in implementing ref() and unref()
// because the control channel is going to keep the worker alive anyway.
function ref() {
}

function unref() {
}

// Faux handle. Mimics a TCPWrap with just enough fidelity to get away
// with it. Fools net.Server into thinking that it's backed by a real
// handle.
var handle = {
close: close,
listen: listen
listen: listen,
ref: ref,
unref: unref,
};
if (message.sockname) {
handle.getsockname = getsockname; // TCP handles only.
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-cluster-rr-ref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');

if (cluster.isMaster) {
cluster.fork().on('message', function(msg) {
if (msg === 'done') this.kill();
});
} else {
const server = net.createServer(assert.fail);
server.listen(common.PORT, function() {
server.unref();
server.ref();
server.close(function() {
process.send('done');
});
});
}