Fixes #16838: yii\mutex\Mutex::acquire() no longer returns true if lock is already acquired by the same component in the same process

This commit is contained in:
Robert Korulczyk
2018-11-04 22:23:24 +01:00
committed by Alexander Makarov
parent 5208ef761e
commit 1fe3d61a3b
4 changed files with 34 additions and 5 deletions

View File

@ -78,6 +78,7 @@ Yii Framework 2 Change Log
- Bug #15204: `yii\helpers\BaseInflector::slug()` is not removing substrings matching provided replacement from given string anymore (bizley)
- Bug #16101: Fixed Error Handler to clear registered meta tags, link tags, css/js scripts and files in error view (bizley)
- Bug #16836: Fix `yii\mutex\MysqlMutex` to handle locks with names longer than 64 characters (rob006)
- Bug #16838: `yii\mutex\Mutex::acquire()` no longer returns `true` if lock is already acquired by the same component in the same process (rob006)
- Enh #16839: Increase frequency of lock tries for `yii\mutex\FileMutex::acquireLock()` when $timeout is provided (rob006)
- Enh #16839: Add support for `$timeout` in `yii\mutex\PgsqlMutex::acquire()` (rob006)
- Bug #16828: `yii\console\controllers\MessageController::translator` recognized object' methods and functions calls as identical sets of tokens (erickskrauch)

View File

@ -62,6 +62,17 @@ Upgrade from Yii 2.0.15
```json
"cebe/markdown": "~1.1.0",
```
* `yii\mutex\Mutex::acquire()` no longer returns `true` if lock is already acquired by the same component in the same process.
Make sure that you're not trying to acquire the same lock multiple times in a way that may create infinite loops, for example:
```php
if (Yii::$app->mutex->acquire('test')) {
while (!Yii::$app->mutex->acquire('test')) {
// `Yii::$app->mutex->acquire('test')` will always return `false` here, since lock is already acquired
}
}
```
Upgrade from Yii 2.0.14

View File

@ -69,7 +69,7 @@ abstract class Mutex extends Component
*/
public function acquire($name, $timeout = 0)
{
if ($this->acquireLock($name, $timeout)) {
if (!in_array($name, $this->_locks, true) && $this->acquireLock($name, $timeout)) {
$this->_locks[] = $name;
return true;