diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index df0c79f..8bd57de 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -64,7 +64,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] type: ['Phpunit', 'Phpunit Lowest'] include: - php: 'latest' diff --git a/composer.json b/composer.json index 3c96fd1..1a950ba 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ ], "homepage": "https://github.com/malkusch/lock", "require": { - "php": ">=7.4 <8.5", + "php": ">=7.4 <8.6", "psr/log": "^1.0 || ^2.0 || ^3.0", "symfony/polyfill-php80": "^1.28" }, @@ -59,7 +59,7 @@ "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^9.5.25 || ^10.0 || ^11.0", "predis/predis": "^1.1.8 || ^2.0", - "spatie/async": "^1.5" + "spatie/async": "^1.5 || ^1.8" }, "suggest": { "ext-igbinary": "To use this library with PHP Redis igbinary serializer enabled.", diff --git a/src/Mutex/DistributedMutex.php b/src/Mutex/DistributedMutex.php index 8ccc862..e84c182 100644 --- a/src/Mutex/DistributedMutex.php +++ b/src/Mutex/DistributedMutex.php @@ -57,7 +57,13 @@ protected function acquireWithToken(string $key, float $expireTimeout) $exception = null; foreach ($this->getMutexesInRandomOrder() as $index => $mutex) { try { - if ($this->acquireMutex($mutex, $key, $acquireTimeout - (microtime(true) - $startTs), $expireTimeout)) { + $remainingTimeout = $acquireTimeout - (microtime(true) - $startTs); + // Prevent INF/NAN from being passed to acquireMutex + if (is_infinite($remainingTimeout) || is_nan($remainingTimeout) || $remainingTimeout < 0) { + $remainingTimeout = 0.0; + } + + if ($this->acquireMutex($mutex, $key, $remainingTimeout, $expireTimeout)) { $acquiredIndexes[] = $index; } } catch (LockAcquireException $exception) { diff --git a/src/Util/LockUtil.php b/src/Util/LockUtil.php index d07add1..2ff3d33 100644 --- a/src/Util/LockUtil.php +++ b/src/Util/LockUtil.php @@ -71,11 +71,13 @@ public function castFloatToInt(float $value): int */ public function formatTimeout(float $value): string { + if (!is_finite($value) || is_nan($value)) { + return '0.0'; + } $res = (string) round($value, 6); - if (\is_finite($value) && strpos($res, '.') === false) { + if (strpos($res, '.') === false) { $res .= '.0'; } - return $res; } }