Skip to content

Commit

Permalink
cluster, net: fix listen pipe with readable and writable in cluster
Browse files Browse the repository at this point in the history
PR-URL: nodejs#43634
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
theanarkh committed Jul 10, 2022
1 parent 3fb5784 commit a933a75
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/internal/cluster/round_robin_handle.js
Expand Up @@ -15,7 +15,7 @@ const { constants } = internalBinding('tcp_wrap');

module.exports = RoundRobinHandle;

function RoundRobinHandle(key, address, { port, fd, flags, backlog }) {
function RoundRobinHandle(key, address, { port, fd, flags, backlog, readableAll, writableAll }) {
this.key = key;
this.all = new SafeMap();
this.free = new SafeMap();
Expand All @@ -34,8 +34,12 @@ function RoundRobinHandle(key, address, { port, fd, flags, backlog }) {
backlog,
});
} else
this.server.listen(address, backlog); // UNIX socket path.

this.server.listen({
path: address,
backlog,
readableAll,
writableAll,
}); // UNIX socket path.
this.server.once('listening', () => {
this.handle = this.server._handle;
this.handle.onconnection = (err, handle) => this.distribute(err, handle);
Expand Down
18 changes: 14 additions & 4 deletions lib/net.js
Expand Up @@ -1467,7 +1467,7 @@ function emitListeningNT(self) {


function listenInCluster(server, address, port, addressType,
backlog, fd, exclusive, flags) {
backlog, fd, exclusive, flags, options) {
exclusive = !!exclusive;

if (cluster === undefined) cluster = require('cluster');
Expand All @@ -1487,8 +1487,8 @@ function listenInCluster(server, address, port, addressType,
fd: fd,
flags,
backlog,
...options,
};

// Get the primary's server handle, and listen on it
cluster._getServer(server, serverQuery, listenOnPrimaryHandle);

Expand Down Expand Up @@ -1575,8 +1575,18 @@ Server.prototype.listen = function(...args) {
if (options.path && isPipeName(options.path)) {
const pipeName = this._pipeName = options.path;
backlog = options.backlog || backlogFromArgs;
listenInCluster(this, pipeName, -1, -1,
backlog, undefined, options.exclusive);
listenInCluster(this,
pipeName,
-1,
-1,
backlog,
undefined,
options.exclusive,
undefined,
{
readableAll: options.readableAll,
writableAll: options.writableAll,
});

if (!this._handle) {
// Failed and an error shall be emitted in the next tick.
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-cluster-listen-pipe-readable-writable.js
@@ -0,0 +1,29 @@
'use strict';
const common = require('../common');

if (common.isWindows) {
common.skip('skip on Windows');
return;
}

const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
const fs = require('fs');

if (cluster.isPrimary) {
cluster.fork();
} else {
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const server = net.createServer().listen({
path: common.PIPE,
readableAll: true,
writableAll: true,
}, common.mustCall(() => {
const stat = fs.statSync(common.PIPE);
assert.strictEqual(stat.mode & 0o777, 0o777);
server.close();
process.disconnect();
}));
}

0 comments on commit a933a75

Please sign in to comment.