Skip to content

Commit fa98b97

Browse files
committed
cluster: add handle ref/unref stubs in rr mode
Add ref() and unref() stub methods to the faux handle in round-robin mode. Fixes the following TypeError when calling `server.unref()` in the worker: net.js:1521 this._handle.unref(); ^ TypeError: this._handle.unref is not a function at Server.unref (net.js:1521:18) No actual reference counting is implemented. It would effectively be a no-op because the control channel would still keep the worker alive. Fixes: #73 PR-URL: #2274 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 3cbb587 commit fa98b97

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/cluster.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,22 @@ function workerInit() {
603603
return 0;
604604
}
605605

606+
// XXX(bnoordhuis) Probably no point in implementing ref() and unref()
607+
// because the control channel is going to keep the worker alive anyway.
608+
function ref() {
609+
}
610+
611+
function unref() {
612+
}
613+
606614
// Faux handle. Mimics a TCPWrap with just enough fidelity to get away
607615
// with it. Fools net.Server into thinking that it's backed by a real
608616
// handle.
609617
var handle = {
610618
close: close,
611-
listen: listen
619+
listen: listen,
620+
ref: ref,
621+
unref: unref,
612622
};
613623
if (message.sockname) {
614624
handle.getsockname = getsockname; // TCP handles only.

test/parallel/test-cluster-rr-ref.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const cluster = require('cluster');
6+
const net = require('net');
7+
8+
if (cluster.isMaster) {
9+
cluster.fork().on('message', function(msg) {
10+
if (msg === 'done') this.kill();
11+
});
12+
} else {
13+
const server = net.createServer(assert.fail);
14+
server.listen(common.PORT, function() {
15+
server.unref();
16+
server.ref();
17+
server.close(function() {
18+
process.send('done');
19+
});
20+
});
21+
}

0 commit comments

Comments
 (0)