The test runner for DMD uses parallel foreach (https://github.com/dlang/dmd/blob/deb039f5f6740d4df0f09226d4ee02c450f75658/compiler/test/run.d#L189):
foreach (target; parallel(targets, 1))
{
log("run: %-(%s %)", target.args);
int status = spawnProcess(target.args, env, Config.none, scriptDir).wait;
if (status != 0)
{
const string name = target.filename
? target.normalizedTestName
: "`unit` tests";
writeln(">>> TARGET FAILED: ", name);
failedTargets ~= name;
}
}
Appending to failedTargets inside the loop body could be a race condition, because parallel can run the loop body from different threads. This could result in a wrong value for failedTargets or crash the test runner.
I don't know if this happens in practice, though.
Comment #1 by dlang-bot — 2023-01-14T21:24:12Z
@ntrel created dlang/dmd pull request #14817 "Fix Issue 23624 - Race condition in test runner for DMD" fixing this issue:
- Fix Issue 23624 - Race condition in test runner for DMD
https://github.com/dlang/dmd/pull/14817
Comment #2 by nick — 2023-01-14T21:29:02Z
Note: ideally `parallel` should not allow this to compile - see issue 15129.
Comment #3 by dlang-bot — 2023-01-15T15:14:16Z
dlang/dmd pull request #14817 "Fix Issue 23624 - Race condition in test runner for DMD" was merged into master:
- dc08042498e0a3a1cb053e0cf53ccefb527f4ad3 by Nick Treleaven:
Fix Issue 23624 - Race condition in test runner for DMD
https://github.com/dlang/dmd/pull/14817