From 5d2d513f973fab7c9cbb7e011791c01c93f8a983 Mon Sep 17 00:00:00 2001 From: Wim Leers Date: Tue, 14 Mar 2023 15:31:25 +0100 Subject: [PATCH] Follow-up for #5205: fix high concurrency race condition Composer would fail with an ``` PHP temp directory (/tmp) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini ``` error when used in parallel. Because it is checking if a file with `md5(microtime())` can be created, which is not sufficiently unique when used in parallel. Since each Composer instance runs in its own process, this can easily be mitigated by not just partitioning based on time of use, but also based on process ID. Original investigation: https://www.drupal.org/project/automatic_updates/issues/3338789#comment-14961390 --- src/Composer/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index bdd6ef6d3..9e585e614 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -339,7 +339,7 @@ class Application extends BaseApplication // Check system temp folder for usability as it can cause weird runtime issues otherwise Silencer::call(static function () use ($io): void { - $tempfile = sys_get_temp_dir() . '/temp-' . md5(microtime()); + $tempfile = sys_get_temp_dir() . '/temp-' . getmypid() . '-' . md5(microtime()); if (!(file_put_contents($tempfile, __FILE__) && (file_get_contents($tempfile) === __FILE__) && unlink($tempfile) && !file_exists($tempfile))) { $io->writeError(sprintf('PHP temp directory (%s) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini', sys_get_temp_dir())); }