diff options
author | laino <lain@volafile.io> | 2018-01-08 23:05:33 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-01-17 06:55:49 +0300 |
commit | 4e2e7d11e16d185a088aec77d1adc7bb4b606806 (patch) | |
tree | 7997d0f058bc84ddc9cef0af49a815e543cf0471 /lib/internal/cluster | |
parent | f878f9414eb6c7ef1d166404ae43444826706db8 (diff) |
cluster: resolve relative unix socket paths
Relative unix sockets paths were previously interpreted relative
to the master's CWD, which was inconsistent with non-cluster behavior.
A test case has been added as well.
PR-URL: https://github.com/nodejs/node/pull/16749
Fixes: https://github.com/nodejs/node/issues/16387
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'lib/internal/cluster')
-rw-r--r-- | lib/internal/cluster/child.js | 12 | ||||
-rw-r--r-- | lib/internal/cluster/master.js | 15 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index 98c5e7b5597..40c1a123275 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -1,6 +1,7 @@ 'use strict'; const assert = require('assert'); const util = require('util'); +const path = require('path'); const EventEmitter = require('events'); const Worker = require('internal/cluster/worker'); const { internal, sendHelper } = require('internal/cluster/utils'); @@ -48,7 +49,14 @@ cluster._setupWorker = function() { // obj is a net#Server or a dgram#Socket object. cluster._getServer = function(obj, options, cb) { - const indexesKey = [options.address, + let address = options.address; + + // Resolve unix socket paths to absolute paths + if (options.port < 0 && typeof address === 'string' && + process.platform !== 'win32') + address = path.resolve(address); + + const indexesKey = [address, options.port, options.addressType, options.fd ].join(':'); @@ -64,6 +72,8 @@ cluster._getServer = function(obj, options, cb) { data: null }, options); + message.address = address; + // Set custom data on handle (i.e. tls tickets key) if (obj._getServerData) message.data = obj._getServerData(); diff --git a/lib/internal/cluster/master.js b/lib/internal/cluster/master.js index 408b31c2b77..280955549ad 100644 --- a/lib/internal/cluster/master.js +++ b/lib/internal/cluster/master.js @@ -2,6 +2,7 @@ const assert = require('assert'); const { fork } = require('child_process'); const util = require('util'); +const path = require('path'); const EventEmitter = require('events'); const RoundRobinHandle = require('internal/cluster/round_robin_handle'); const SharedHandle = require('internal/cluster/shared_handle'); @@ -276,6 +277,18 @@ function queryServer(worker, message) { var handle = handles[key]; if (handle === undefined) { + let address = message.address; + + // Find shortest path for unix sockets because of the ~100 byte limit + if (message.port < 0 && typeof address === 'string' && + process.platform !== 'win32') { + + address = path.relative(process.cwd(), address); + + if (message.address.length < address.length) + address = message.address; + } + var constructor = RoundRobinHandle; // UDP is exempt from round-robin connection balancing for what should // be obvious reasons: it's connectionless. There is nothing to send to @@ -287,7 +300,7 @@ function queryServer(worker, message) { } handles[key] = handle = new constructor(key, - message.address, + address, message.port, message.addressType, message.fd, |