From cfcbc75de92de8e7d622181bf15c0bf4fbf6297b Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 31 Mar 2022 06:29:21 -0700 Subject: [PATCH] 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 --- .../flipper-server/src/startBaseServer.tsx | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/desktop/flipper-server/src/startBaseServer.tsx b/desktop/flipper-server/src/startBaseServer.tsx index 67efb41ea..b6c664d6b 100644 --- a/desktop/flipper-server/src/startBaseServer.tsx +++ b/desktop/flipper-server/src/startBaseServer.tsx @@ -93,6 +93,25 @@ async function checkSocketInUse(path: string): Promise { }); } +async function makeSocketPath(): Promise { + 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( config: Config, app: Express, @@ -107,9 +126,7 @@ async function startProxyServer( }); } - const runtimeDir = xdgBasedir.runtime || '/tmp'; - await fs.mkdirp(runtimeDir); - const socketPath = `${runtimeDir}/flipper-server-${userInfo().uid}.sock`; + const socketPath = await makeSocketPath(); if (await checkSocketInUse(socketPath)) { console.warn(