Skip to content

Commit

Permalink
fix(cluster): respect the backlog from workers
Browse files Browse the repository at this point in the history
Currently, the master process would ignore `backlog` from worker
processes and use the default value instead. This commit will respect
the first `backlog` passed to the master process for a specific handle.

Refs: nodejs#4056
  • Loading branch information
oyyd committed Jun 10, 2020
1 parent 362e4a1 commit 71380c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ server.listen({
});
```

When `exclusive` is `true` and the underlying handle is shared, it's
possible that several workers query a handle with different backlogs.
In this case, the first `backlog` passed to the master process will be used.

Starting an IPC server as root may cause the server path to be inaccessible for
unprivileged users. Using `readableAll` and `writableAll` will make the server
accessible for all users.
Expand Down
7 changes: 4 additions & 3 deletions lib/internal/cluster/round_robin_handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { constants } = internalBinding('tcp_wrap');

module.exports = RoundRobinHandle;

function RoundRobinHandle(key, address, { port, fd, flags }) {
function RoundRobinHandle(key, address, { port, fd, flags, backlog }) {
this.key = key;
this.all = new Map();
this.free = new Map();
Expand All @@ -22,16 +22,17 @@ function RoundRobinHandle(key, address, { port, fd, flags }) {
this.server = net.createServer(assert.fail);

if (fd >= 0)
this.server.listen({ fd });
this.server.listen({ fd, backlog });
else if (port >= 0) {
this.server.listen({
port,
host: address,
// Currently, net module only supports `ipv6Only` option in `flags`.
ipv6Only: Boolean(flags & constants.UV_TCP_IPV6ONLY),
backlog,
});
} else
this.server.listen(address); // UNIX socket path.
this.server.listen(address, backlog); // UNIX socket path.

this.server.once('listening', () => {
this.handle = this.server._handle;
Expand Down
1 change: 1 addition & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ function listenInCluster(server, address, port, addressType,
addressType: addressType,
fd: fd,
flags,
backlog,
};

// Get the master's server handle, and listen on it
Expand Down

0 comments on commit 71380c5

Please sign in to comment.