Skip to content

Commit 90f7adc

Browse files
authored
fix(utils): unique names for parallel plugin execution (#1222)
1 parent 1d7ffda commit 90f7adc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { writeFile } from 'node:fs/promises';
22
import path from 'node:path';
3+
import { threadId } from 'node:worker_threads';
34
import type { RunnerFilesPaths } from '@code-pushup/models';
45
import { ensureDirectoryExists, pluginWorkDir } from './file-system.js';
56

@@ -13,8 +14,10 @@ export async function createRunnerFiles(
1314
pluginSlug: string,
1415
configJSON: string,
1516
): Promise<RunnerFilesPaths> {
16-
const timestamp = Date.now().toString();
17-
const runnerWorkDir = path.join(pluginWorkDir(pluginSlug), timestamp);
17+
// Use timestamp + process ID + threadId
18+
// This prevents race conditions when running the same plugin for multiple projects in parallel
19+
const uniqueId = `${(performance.timeOrigin + performance.now()) * 10}-${process.pid}-${threadId}`;
20+
const runnerWorkDir = path.join(pluginWorkDir(pluginSlug), uniqueId);
1821
const runnerConfigPath = path.join(runnerWorkDir, 'plugin-config.json');
1922
const runnerOutputPath = path.join(runnerWorkDir, 'runner-output.json');
2023

0 commit comments

Comments
 (0)