Skip to content

Unix domain path too long when using pipe as transport for macOS on Apple Silicon #1346

Closed

Description

VS Code Java extension is experimenting with using pipes as the transport mechanism between the language client and the Java language server. However, the automatically generated pipe paths for macOS on Silicon (such as /var/folders/c4/f8v01p_s2sn9_hrx6y18dlxr0000gq/T/vscode-b4e4949e2fde772119c33ebd3ad375f0e8b742abf2.sock) are too long and exceed the OS domain socket limit. See the generateRandomPipeName function in language client, it uses 21 random bytes (which is converted to 42 characters) as suffix, can we reduce the random suffix to a lower value?

export function generateRandomPipeName(): string {
const randomSuffix = randomBytes(21).toString('hex');
if (process.platform === 'win32') {
return `\\\\.\\pipe\\vscode-jsonrpc-${randomSuffix}-sock`;
}
let result: string;
if (XDG_RUNTIME_DIR) {
result = path.join(XDG_RUNTIME_DIR, `vscode-ipc-${randomSuffix}.sock`);
} else {
result = path.join(os.tmpdir(), `vscode-${randomSuffix}.sock`);
}
const limit = safeIpcPathLengths.get(process.platform);
if (limit !== undefined && result.length > limit) {
RIL().console.warn(`WARNING: IPC handle "${result}" is longer than ${limit} characters.`);
}
return result;

See the original issues on Java extension for more context information.

// Dirk Bäumer (@dbaeumer) WDYT?

Activity

  1. testforstephen commented on Oct 31, 2023

    @testforstephen
    Author

    The tmp directory /var/folders/… (generated by os.tmpdir()) is actually a symlink to /private/var/folders/…, which has a longer path. This causes the pipe path to exceed the 103 characters limit on macOS. We need to find a way to shorten the pipe path for macOS.

  2. dbaeumer commented on Oct 31, 2023

    @dbaeumer
    Member

    I recoded the code a little that generates the pipe name.

    function generateRandomPipeName() {
        if (process.platform === 'win32') {
            return `\\\\.\\pipe\\lsp-${(0, crypto_1.randomBytes)(16).toString('hex')}-sock`;
        }
        let randomLength = 32;
        const fixedLength = 'lsp-.sock'.length;
        const tmpDir = 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.`);
        }
        const randomSuffix = (0, crypto_1.randomBytes)(Math.floor(randomLength / 2)).toString('hex');
        return path.join(tmpDir, `lsp-${randomSuffix}.sock`);
    }

    Jinbo Wang (@testforstephen) could you patch the JS code in the lib folder to see if this works for you under Mac

  3. added
    bugIssue identified by VS Code Team member as probable bug
    info-neededIssue requires more information from poster
    on Oct 31, 2023
  4. testforstephen commented on Nov 1, 2023

    @testforstephen
    Author

    Dirk Bäumer (@dbaeumer) thanks for the quick patch.

    I can confirm the patch works well on macOS M2 machine, which generates a new pipe path in the format of /private/var/folders/j9/2657q9qj5mgc31phjzjz_g8r0000gq/T/lsp-9b5c0dd5f8a89159ce06a26866a2c94c.sock.

    I also tried it in Windows 10 and WSL (ubuntu 20), the new pipe format works.

  5. dbaeumer commented on Nov 1, 2023

    @dbaeumer
    Member

    I will prepare a next release so that you can try to publish something.

  6. karthiknadig commented on Nov 3, 2023

    @karthiknadig
    Member

    related: #1351

  7. dbaeumer commented on Nov 6, 2023

    @dbaeumer
    Member

    I released 9.0.2-next.1 which contains the new code to compute the pipe name

  8. added this to the Next milestone on Nov 6, 2023
  9. modified the milestones: Next, on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from poster

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions