1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 16:42:57 +00:00

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: 3338789 (comment-14961390)
This commit is contained in:
Wim Leers 2023-03-14 15:31:25 +01:00 committed by Jordi Boggiano
parent 32366bc37d
commit 5d2d513f97
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC

View file

@ -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('<error>PHP temp directory (%s) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini</error>', sys_get_temp_dir()));
}