894
895
export function createRandomIPCHandle(): string {
896
>
const randomSuffix = generateUuid();
ipc.net.ts
897
>
898
>
// Windows: use named pipe
899
>
if (process.platform === 'win32') {
900
return `\\\\.\\pipe\\vscode-ipc-${randomSuffix}-sock`;
901
}
903
>
// Mac & Unix: Use socket file
904
>
// Unix: Prefer XDG_RUNTIME_DIR over user data path
905
>
const basePath = process.platform !== 'darwin' && XDG_RUNTIME_DIR ? XDG_RUNTIME_DIR : tmpdir();
906
>
907
>
// As of Node.js 24, socket paths that exceed the
908
>
// platform limit cause an `EINVAL` error at bind time instead of being silently
909
>
// truncated. The suffix only needs to be unique, so trim it (while keeping enough
910
>
// entropy) to make the path fit within the limit.
911
>
// See https://github.com/nodejs/node/commit/75884678d7e7ef228c8f8f82b4c085258c70a823
912
>
const limit = safeIpcPathLengths[platform];
913
>
let suffix = randomSuffix;
914
>
if (typeof limit === 'number') {
915
>
const available = Math.max(0, (limit - 1) - join(basePath, `vscode-ipc-.sock`).length);
916
>
if (available < suffix.length) {
917
suffix = suffix.slice(0, available);
918
}
920
>
921
>
return join(basePath, `vscode-ipc-${suffix}.sock`);
922
>
}
923
924
export function createStaticIPCHandle(directoryPath: string, type: string, version: string): string {