Skip to content
Closed
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
Prev Previous commit
fixup! fix(cluster): respect the backlog from workers
  • Loading branch information
oyyd committed Aug 18, 2020
commit 4dcefb44bf31d6bb317cbbed53a7ea07dd692742
32 changes: 15 additions & 17 deletions test/parallel/test-cluster-net-listen-backlog.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
'use strict';

const common = require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
// Monkey-patch `net.Server._listen2`
// Monkey-patch `net.Server.listen`
const net = require('net');
const cluster = require('cluster');

// Ensures that the `backlog` is used to create a `net.Server`.
const kExpectedBacklog = 127;
if (cluster.isMaster) {
let worker
const listen = net.Server.prototype.listen;

const nativeListen = net.Server.prototype._listen2;
const countdown = new Countdown(2, () => {
worker.disconnect();
});

net.Server.prototype._listen2 = common.mustCall(
function(address, port, addressType, backlog, fd, flags) {
assert(backlog, kExpectedBacklog);
countdown.dec();
return nativeListen.call(this, address, port, addressType, backlog, fd, flags);
net.Server.prototype.listen = common.mustCall(
function(...args) {
const options = args[0];
if (typeof options === 'object') {
assert(options.backlog, kExpectedBacklog);
} else {
assert(args[1], kExpectedBacklog);
}
return listen.call(this, ...args);
}
);

worker = cluster.fork();
const worker = cluster.fork();
worker.on('message', () => {
countdown.dec();
worker.disconnect();
});
} else {
const server = net.createServer()
const server = net.createServer();

server.listen({
host: common.localhostIPv4,
port: 0,
Expand Down