cluster, net: fix listen pipe with readable and writable in cluster

PR-URL: https://github.com/nodejs/node/pull/43634
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
theanarkh authored and Michaël Zasso committed 2022-07-31 09:45:15 +02:00
1 parent 5a74939770
commit c8706f3a7f
3 files changed
+50 -7

No files matched your search

+7 -3
View File
@@ -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);
+14 -4
View File
@@ -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.
@@ -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();
}));
}