From 69f36c4e58de370b38f21c5c5bd8b12aea9051f3 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Wed, 28 Aug 2024 11:30:57 +0800 Subject: [PATCH] fix - Fallback to /tmp/ when named pipe is too long (#1591) --- .../com/microsoft/gradle/bs/importer/NamedPipeStream.java | 3 ++- extension/src/util/generateRandomPipeName.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java index 7447afee6..ab741f642 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java @@ -128,7 +128,8 @@ private String generateRandomPipeName() { randomLength = Math.min(limit - tmpDir.length() - fixedLength, randomLength); } if (randomLength < 16) { - throw new NamedPipeConnectionException("Unable to generate a random pipe name with character length less than 16"); + tmpDir = "/tmp/"; + JavaLanguageServerPlugin.logInfo("length of random pipe name too long, using /tmp/ as tmpDir"); } String randomSuffix = generateRandomHex(randomLength/2); diff --git a/extension/src/util/generateRandomPipeName.ts b/extension/src/util/generateRandomPipeName.ts index 3559bbfe5..d3714c885 100644 --- a/extension/src/util/generateRandomPipeName.ts +++ b/extension/src/util/generateRandomPipeName.ts @@ -19,13 +19,16 @@ function generateRandomPipeName(): string { let randomLength = 32; const fixedLength = ".sock".length; - const tmpDir: string = fs.realpathSync(XDG_RUNTIME_DIR ?? os.tmpdir()); + let tmpDir: string = fs.realpathSync(XDG_RUNTIME_DIR ?? os.tmpdir()); const limit = safeIpcPathLengths.get(process.platform); if (limit !== undefined) { randomLength = Math.min(limit - tmpDir.length - fixedLength, randomLength); } if (randomLength < 16) { - throw new Error(`Unable to generate a random pipe name with ${randomLength} characters.`); + sendInfo("", { + kind: "tempDirTooLongWhenGenerateRandomPipeName", + }); + tmpDir = "/tmp/"; } const randomSuffix = randomBytes(Math.floor(randomLength / 2)).toString("hex");