-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #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>
- Loading branch information
1 parent
fd845d8
commit 087cdaf
Showing
3 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
const net = require('net'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
if (common.isWindows) | ||
common.skip('On Windows named pipes live in their own ' + | ||
'filesystem and don\'t have a ~100 byte limit'); | ||
|
||
// Choose a socket name such that the absolute path would exceed 100 bytes. | ||
const socketDir = './unix-socket-dir'; | ||
const socketName = 'A'.repeat(100 - socketDir.length - 1); | ||
|
||
// Make sure we're not in a weird environment | ||
assert.strictEqual(path.resolve(socketDir, socketName).length > 100, true, | ||
'absolute socket path should be longer than 100 bytes'); | ||
|
||
if (cluster.isMaster) { | ||
// ensure that the worker exits peacefully | ||
process.chdir(common.tmpDir); | ||
fs.mkdirSync(socketDir); | ||
cluster.fork().on('exit', common.mustCall(function(statusCode) { | ||
assert.strictEqual(statusCode, 0); | ||
|
||
assert.strictEqual( | ||
fs.existsSync(path.join(socketDir, socketName)), false, | ||
'Socket should be removed when the worker exits'); | ||
})); | ||
} else { | ||
process.chdir(socketDir); | ||
|
||
const server = net.createServer(common.mustNotCall()); | ||
|
||
server.listen(socketName, common.mustCall(function() { | ||
assert.strictEqual( | ||
fs.existsSync(socketName), true, | ||
'Socket created in CWD'); | ||
|
||
process.disconnect(); | ||
})); | ||
} |