Take unix domain socket max length into account

Summary: lawrencelomax helpfully pointed out that there's a legacy limit for the path length of unix domain sockets. Checking here and falling back to `/tmp` in case we're going over. This could have caused some gnarly support issues, so I'm glad we caught this before it went live.

Reviewed By: aigoncharov

Differential Revision: D35257794

fbshipit-source-id: 68a7b62d6d6863efa4b3ce84d7735b1c1a45a174
This commit is contained in:
Pascal Hartig
2022-03-31 06:29:21 -07:00
committed by Facebook GitHub Bot
parent 5ce82405f7
commit cfcbc75de9

View File

@@ -93,6 +93,25 @@ async function checkSocketInUse(path: string): Promise<boolean> {
}); });
} }
async function makeSocketPath(): Promise<string> {
const runtimeDir = xdgBasedir.runtime || '/tmp';
await fs.mkdirp(runtimeDir);
const filename = `flipper-server-${os.userInfo().uid}.sock`;
const path = `${runtimeDir}/${filename}`;
// Depending on the OS this is between 104 and 108:
// https://unix.stackexchange.com/a/367012/10198
if (path.length >= 104) {
console.warn(
'Ignoring XDG_RUNTIME_DIR as it would exceed the total limit for domain socket paths. See man 7 unix.',
);
// Even with the INT32_MAX userid, we should have plenty of room.
return `/tmp/${filename}`;
}
return path;
}
async function startProxyServer( async function startProxyServer(
config: Config, config: Config,
app: Express, app: Express,
@@ -107,9 +126,7 @@ async function startProxyServer(
}); });
} }
const runtimeDir = xdgBasedir.runtime || '/tmp'; const socketPath = await makeSocketPath();
await fs.mkdirp(runtimeDir);
const socketPath = `${runtimeDir}/flipper-server-${userInfo().uid}.sock`;
if (await checkSocketInUse(socketPath)) { if (await checkSocketInUse(socketPath)) {
console.warn( console.warn(