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 listen doesn't resolve UNIX domain socket paths relative to worker CWD #16387

Closed
laino opened this issue Oct 22, 2017 · 2 comments
Closed
Labels
cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem.

Comments

@laino
Copy link

laino commented Oct 22, 2017

  • Version: v8.6.0
  • Subsystem: net, cluster

When calling server.listen('./socket.sock') in a worker, the relative path is passed as-is to the master,
causing the path to be relative to the master's CWD, instead of the child process' CWD.

This behavior is inconsistent with listen(...) outside of a worker.

Here's a short example illustrating the issue:

const cluster = require('cluster');
const http = require('http');

if (cluster.isMaster) {
    cluster.fork();
} else {
    const server = http.createServer();
    process.chdir('/tmp');
    server.listen("./test.sock");
}

Expected outcome: test.sock is created in /tmp.
Actual outcome: test.sock is created in the previous directory.

Solution:

UNIX domain socket paths should immediately be resolved to absolute paths using path.resolve(...)
before anything else is done with them (such as passing them to the master process).

@addaleax addaleax added cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem. labels Oct 22, 2017
@addaleax
Copy link
Member

Yes, this sounds like a bug, thanks for reporting.

One thing that makes this tricky: There is a pretty short path limit (~100 bytes) on what can be passed to .listen(), so we’ve been forced to migrate to using relative paths in Node’s own test suite to keep them short enough.

@laino
Copy link
Author

laino commented Oct 22, 2017

We could call path.relative(process.cwd(), socketPath) in the master right before the actual call to listen, then take whichever is shorter: the absolute path or the relative path.

laino pushed a commit to laino/node.js that referenced this issue Jan 8, 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.

Fixes: nodejs#16387
evanlucas pushed a commit that referenced this issue 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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this issue 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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
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. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants