From def20f29ca1da0fa327a845bc7e6c07bd58ccdcb Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Wed, 24 Jul 2024 15:42:24 -0400 Subject: [PATCH] fix(core): shorten socket length for plugin workers (#27073) ## Current Behavior Plugin worker's socket path includes a hash digest of the workspace root. This is not needed, as the socket path already includes the process pid in it which is unique. The hash digest adds an additional 20 characters to the path and as the path is too long on some unix systems the uniqueness is dropped, causing the plugin transactions to get hit inappropriately. ## Expected Behavior The plugin socket path doesn't contain extra characters, so it should be unique. ## Related Issue(s) Possibly related #27040 --- packages/nx/src/daemon/socket-utils.ts | 2 +- packages/nx/src/daemon/tmp-dir.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/nx/src/daemon/socket-utils.ts b/packages/nx/src/daemon/socket-utils.ts index 3cf2640613..c97f92f1e6 100644 --- a/packages/nx/src/daemon/socket-utils.ts +++ b/packages/nx/src/daemon/socket-utils.ts @@ -23,7 +23,7 @@ export const getForkedProcessOsSocketPath = (id: string) => { }; export const getPluginOsSocketPath = (id: string) => { - let path = resolve(join(getSocketDir(), 'plugin' + id + '.sock')); + let path = resolve(join(getSocketDir(true), 'plugin' + id + '.sock')); return isWindows ? '\\\\.\\pipe\\nx\\' + resolve(path) : resolve(path); }; diff --git a/packages/nx/src/daemon/tmp-dir.ts b/packages/nx/src/daemon/tmp-dir.ts index a865439486..0d163aef47 100644 --- a/packages/nx/src/daemon/tmp-dir.ts +++ b/packages/nx/src/daemon/tmp-dir.ts @@ -58,9 +58,11 @@ function socketDirName() { * We try to create a socket file in a tmp dir, but if it doesn't work because * for instance we don't have permissions, we create it in DAEMON_DIR_FOR_CURRENT_WORKSPACE */ -export function getSocketDir() { +export function getSocketDir(alreadyUnique = false) { try { - const dir = process.env.NX_DAEMON_SOCKET_DIR ?? socketDirName(); + const dir = + process.env.NX_DAEMON_SOCKET_DIR ?? + (alreadyUnique ? tmpdir : socketDirName()); ensureDirSync(dir); return dir; } catch (e) {