Skip to content

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

@laino

Description

@laino
  • 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clusterIssues and PRs related to the cluster subsystem.netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions