Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: correctly handle relative unix socket paths #16749

Closed
wants to merge 1 commit into from

Conversation

laino
Copy link

@laino laino commented Nov 4, 2017

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.

I only added the "find the shortest possible path for unix sockets" to the cluster code, so that
outside of workers the net API would still map to the actual syscalls happening under the hood
cleanly.

Fixes: #16387

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

net, cluster

@nodejs-github-bot nodejs-github-bot added the cluster Issues and PRs related to the cluster subsystem. label Nov 4, 2017
@mscdex
Copy link
Contributor

mscdex commented Nov 4, 2017

I feel like this should be done more upstream (in node core) to avoid having to potentially call path methods very often.

@@ -58,11 +65,13 @@ cluster._getServer = function(obj, options, cb) {
else
indexes[indexesKey]++;

const message = util._extend({
const message = Object.assign({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we are still using util._extend() instead Object.assign() for performance reasons.

@@ -0,0 +1,45 @@
// Copyright Joyent, Inc. and other Node contributors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests don't need the copyright comment.

}));
} else {
process.chdir('./unix-socket-dir');
net.createServer(common.mustNotCall()).listen('./cluster.sock', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a common.mustCall() to the callback.

fs.existsSync('./cluster.sock'), true,
'cluster.sock created in CWD');

process.exit(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of forcing the exit, can you cleanup as necessary and let the process exit naturally.

@laino
Copy link
Author

laino commented Nov 4, 2017

Do you like your PR commits --amend'ed or with a second commit?

@addaleax
Copy link
Member

addaleax commented Nov 4, 2017

@laino Whatever is easier for you :) We’re going to squash commits when landing them anyway

@laino
Copy link
Author

laino commented Nov 15, 2017

Hey, is there anything else that needs changing for this to be merged?

@joyeecheung
Copy link
Member

@joyeecheung
Copy link
Member

joyeecheung commented Nov 21, 2017

@laino Related failures on all Windows builds:

not ok 79 parallel/test-cluster-net-listen-relative-path
  ---
  duration_ms: 0.606
  severity: fail
  stack: |-
    events.js:136
          throw er; // Unhandled 'error' event
          ^
    
    Error: bind EACCES ./cluster.sock
        at Object._errnoException (util.js:1010:13)
        at _exceptionWithHostPort (util.js:1031:20)
        at listenOnMasterHandle (net.js:1427:16)
        at rr (internal/cluster/child.js:120:12)
        at Worker.send (internal/cluster/child.js:87:7)
        at process.onInternalMessage (internal/cluster/utils.js:42:8)
        at process.emit (events.js:164:20)
        at emit (internal/child_process.js:790:12)
        at _combinedTickCallback (internal/process/next_tick.js:140:11)
        at process._tickCallback (internal/process/next_tick.js:179:9)
    assert.js:42
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 1 === 0
        at Worker.<anonymous> (c:\workspace\node-test-binary-windows\test\parallel\test-cluster-net-listen-relative-path.js:13:12)
        at Worker.<anonymous> (c:\workspace\node-test-binary-windows\test\common\index.js:522:15)
        at Worker.emit (events.js:159:13)
        at ChildProcess.worker.process.once (internal/cluster/master.js:185:12)
        at Object.onceWrapper (events.js:254:19)
        at ChildProcess.emit (events.js:159:13)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
  ...

@laino
Copy link
Author

laino commented Nov 21, 2017

@joyeecheung That's the test I added with this PR. It should probably be disabled on windows, but I'm not sure. I don't know much about named pipes on windows.

@laino
Copy link
Author

laino commented Nov 21, 2017

I'll check tomorrow whether there's any tests for named pipes at all for windows, since I'm worried now this might break something. Also I should probably change https://github.com/nodejs/node/pull/16749/files#diff-a8eff7604cf3ad3580c1949c54176127R282 to only happen on Linux, since it doesn't make much sense on systems that don't have the arbitrary 100 byte limitation.

@refack
Copy link
Contributor

refack commented Nov 21, 2017

Hello @laino, Welcome, and thank you for the contribution! 🥇

Named pipes on Windows live in their own FS namespace, and must be prefixed with \\\\.\\pipe\\. So yes the change is only relevant if (process.platform != 'win32' || !address.startsWith('\\\\.\\pipe\\')).
As for the test, I'd make a socket name 'xy'.repeat(45), so that full path will be > 92 while relative will be 92. For skipping put this just after the definition of common at the top of the file:

if (common.isWindows)
  common.skip('no 100 byte limit on pipe names on Windows');

@addaleax
Copy link
Member

ping @laino ... If you have the opportunity, could you try to fix this on Windows, or if not, could you let us know?

@BridgeAR
Copy link
Member

BridgeAR commented Jan 5, 2018

Ping @laino

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.

Fixes: nodejs#16387
@laino
Copy link
Author

laino commented Jan 8, 2018

@laino
Copy link
Author

laino commented Jan 8, 2018

Sorry, I had all but forgotten about this PR.

I made sure the test won't run on windows and that the code to deal with unix domain sockets
won't do anything on windows platforms.

@joyeecheung
Copy link
Member

@laino
Copy link
Author

laino commented Jan 10, 2018

https://ci.nodejs.org/job/node-test-commit-arm/13003/nodes=ubuntu1604-arm64_odroid_c2/console

This is the build that failed. Doesn't seem to be related to this?

@joyeecheung
Copy link
Member

@laino That's a known OOM issue, the CI looks green to me.


// Ref:
// https://github.com/nodejs/node/issues/16387
// https://github.com/nodejs/node/pull/16749
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These refs can be removed during landing. They should be in the metadata, not in the comments.

@joyeecheung joyeecheung added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 10, 2018
@joyeecheung
Copy link
Member

@joyeecheung
Copy link
Member

Landed in 4e2e7d1, thanks!

joyeecheung pushed a commit that referenced this pull request Jan 17, 2018
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: #16749
Fixes: #16387
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
@addaleax addaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 18, 2018
@bnoordhuis
Copy link
Member

Back-porters: should be back-ported along with #18263.

evanlucas pushed a commit that referenced this pull request Jan 30, 2018
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: #16749
Fixes: #16387
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

MylesBorins pushed a commit that referenced this pull request Feb 27, 2018
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: #16749
Fixes: #16387
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
@refack refack removed their assignment Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cluster Issues and PRs related to the cluster subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cluster listen doesn't resolve UNIX domain socket paths relative to worker CWD