Skip to content

Commit 0251404

Browse files
committed
fix(utils): prevent race condition in parallel plugin runs
When running the same plugin for multiple projects in parallel (e.g., via Nx targets), the timestamp-based directory naming could collide if two processes started within the same millisecond. This caused one process to delete the output directory while another was still using it, leading to failures. The fix adds process.pid and a random suffix to the directory name, ensuring uniqueness even when multiple processes run simultaneously.
1 parent 1d7ffda commit 0251404

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/utils/src/lib/create-runner-files.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export async function createRunnerFiles(
1313
pluginSlug: string,
1414
configJSON: string,
1515
): Promise<RunnerFilesPaths> {
16-
const timestamp = Date.now().toString();
17-
const runnerWorkDir = path.join(pluginWorkDir(pluginSlug), timestamp);
16+
// Use timestamp + process ID + random suffix to ensure uniqueness
17+
// This prevents race conditions when running the same plugin for multiple projects in parallel
18+
const uniqueId = `${Date.now()}-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
19+
const runnerWorkDir = path.join(pluginWorkDir(pluginSlug), uniqueId);
1820
const runnerConfigPath = path.join(runnerWorkDir, 'plugin-config.json');
1921
const runnerOutputPath = path.join(runnerWorkDir, 'runner-output.json');
2022

0 commit comments

Comments
 (0)