From c8706f3a7ff53e6fe1da18b7191d4f72640eff25 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Sun, 10 Jul 2022 21:17:32 +0800 Subject: [PATCH] cluster, net: fix listen pipe with readable and writable in cluster PR-URL: https://github.com/nodejs/node/pull/43634 Reviewed-By: Paolo Insogna Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel --- lib/internal/cluster/round_robin_handle.js | 10 +++++-- lib/net.js | 18 +++++++++--- ...t-cluster-listen-pipe-readable-writable.js | 29 +++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 test/parallel/test-cluster-listen-pipe-readable-writable.js diff --git a/lib/internal/cluster/round_robin_handle.js b/lib/internal/cluster/round_robin_handle.js index 9d242cc60ad7c1..a881ca10bcb9de 100644 --- a/lib/internal/cluster/round_robin_handle.js +++ b/lib/internal/cluster/round_robin_handle.js @@ -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(); @@ -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); diff --git a/lib/net.js b/lib/net.js index 12ba9b140a9ba4..9670a662a996ea 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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'); @@ -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); @@ -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. diff --git a/test/parallel/test-cluster-listen-pipe-readable-writable.js b/test/parallel/test-cluster-listen-pipe-readable-writable.js new file mode 100644 index 00000000000000..d4b758a374f670 --- /dev/null +++ b/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(); + })); +}