Skip to content

Commit

Permalink
fix - Fallback to /tmp/ when named pipe is too long (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Aug 28, 2024
1 parent 4038148 commit 69f36c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions extension/src/util/generateRandomPipeName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 69f36c4

Please sign in to comment.