Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
testforstephen opened this issue Oct 31, 2023 · 6 comments
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Milestone

Comments

@testforstephen
Copy link

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.

// @dbaeumer WDYT?

@testforstephen
Copy link
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.

@dbaeumer
Copy link
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`);
}

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

@dbaeumer dbaeumer added bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster labels Oct 31, 2023
@testforstephen
Copy link
Author

@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.

@dbaeumer
Copy link
Member

dbaeumer commented Nov 1, 2023

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

@karthiknadig
Copy link
Member

related: #1351

@dbaeumer
Copy link
Member

dbaeumer commented Nov 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants