Skip to content

Commit 2d00d90

Browse files
cataphractclaude
andcommitted
Fix parallel test race condition in lib.inc temp dir creation
tempnam(__DIR__, '.tmp') + unlink + mkdir has a TOCTOU window: another parallel worker can call tempnam and get the same name after unlink but before mkdir. With -j8 and all tests sharing __DIR__ (the run-tests --temp-source/target dir), this reliably causes "File exists" and "Resource temporarily unavailable" failures on Windows. Replace with a loop on mkdir using PID + uniqid: the PID isolates each concurrent test process, and mkdir is atomic so no window exists. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b4b821e commit 2d00d90

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

tests/lib.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
function get_temp_dir() {
44
static $dir;
55
if (!$dir) {
6-
$dir = tempnam(__DIR__, '.tmp');
7-
unlink($dir);
8-
mkdir($dir);
6+
do {
7+
$dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR
8+
. 'phpla_' . getmypid() . '_' . uniqid();
9+
} while (!@mkdir($dir, 0700));
910

1011
register_shutdown_function(function() use ($dir) {
1112
$files = new RecursiveIteratorIterator(

0 commit comments

Comments
 (0)