Skip to content

Commit fa5c464

Browse files
theanarkhtargos
authored andcommitted
cluster, net: fix listen pipe with readable and writable in cluster
PR-URL: #43634 Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent dc484b6 commit fa5c464

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

lib/internal/cluster/round_robin_handle.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { constants } = internalBinding('tcp_wrap');
1515

1616
module.exports = RoundRobinHandle;
1717

18-
function RoundRobinHandle(key, address, { port, fd, flags, backlog }) {
18+
function RoundRobinHandle(key, address, { port, fd, flags, backlog, readableAll, writableAll }) {
1919
this.key = key;
2020
this.all = new SafeMap();
2121
this.free = new SafeMap();
@@ -34,8 +34,12 @@ function RoundRobinHandle(key, address, { port, fd, flags, backlog }) {
3434
backlog,
3535
});
3636
} else
37-
this.server.listen(address, backlog); // UNIX socket path.
38-
37+
this.server.listen({
38+
path: address,
39+
backlog,
40+
readableAll,
41+
writableAll,
42+
}); // UNIX socket path.
3943
this.server.once('listening', () => {
4044
this.handle = this.server._handle;
4145
this.handle.onconnection = (err, handle) => this.distribute(err, handle);

lib/net.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ function emitListeningNT(self) {
14671467

14681468

14691469
function listenInCluster(server, address, port, addressType,
1470-
backlog, fd, exclusive, flags) {
1470+
backlog, fd, exclusive, flags, options) {
14711471
exclusive = !!exclusive;
14721472

14731473
if (cluster === undefined) cluster = require('cluster');
@@ -1487,8 +1487,8 @@ function listenInCluster(server, address, port, addressType,
14871487
fd: fd,
14881488
flags,
14891489
backlog,
1490+
...options,
14901491
};
1491-
14921492
// Get the primary's server handle, and listen on it
14931493
cluster._getServer(server, serverQuery, listenOnPrimaryHandle);
14941494

@@ -1575,8 +1575,18 @@ Server.prototype.listen = function(...args) {
15751575
if (options.path && isPipeName(options.path)) {
15761576
const pipeName = this._pipeName = options.path;
15771577
backlog = options.backlog || backlogFromArgs;
1578-
listenInCluster(this, pipeName, -1, -1,
1579-
backlog, undefined, options.exclusive);
1578+
listenInCluster(this,
1579+
pipeName,
1580+
-1,
1581+
-1,
1582+
backlog,
1583+
undefined,
1584+
options.exclusive,
1585+
undefined,
1586+
{
1587+
readableAll: options.readableAll,
1588+
writableAll: options.writableAll,
1589+
});
15801590

15811591
if (!this._handle) {
15821592
// Failed and an error shall be emitted in the next tick.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (common.isWindows) {
5+
common.skip('skip on Windows');
6+
return;
7+
}
8+
9+
const assert = require('assert');
10+
const cluster = require('cluster');
11+
const net = require('net');
12+
const fs = require('fs');
13+
14+
if (cluster.isPrimary) {
15+
cluster.fork();
16+
} else {
17+
const tmpdir = require('../common/tmpdir');
18+
tmpdir.refresh();
19+
const server = net.createServer().listen({
20+
path: common.PIPE,
21+
readableAll: true,
22+
writableAll: true,
23+
}, common.mustCall(() => {
24+
const stat = fs.statSync(common.PIPE);
25+
assert.strictEqual(stat.mode & 0o777, 0o777);
26+
server.close();
27+
process.disconnect();
28+
}));
29+
}

0 commit comments

Comments
 (0)