#19316 fix MysqlMutex long name (#19614)

Co-authored-by: Márton Somogyi <somogyi.marton@metrisoft.hu>
This commit is contained in:
Somogyi Márton
2022-10-09 20:21:09 +02:00
committed by GitHub
parent 4aad60fd87
commit 381c266443
3 changed files with 19 additions and 2 deletions

View File

@ -16,6 +16,7 @@ Yii Framework 2 Change Log
- Bug #19589: Fix Error reporting in to the `BaseArrayHelper::getValue()` (lav45)
- Bug #19316: Fix MysqlMutex with same connection but difference database (kamarton)
- Bug #19507: Fix eager loading of nested one-to-many relations (spo0okie)
- Bug #19316: Fix MysqlMutex long name (kamarton)
2.0.46 August 18, 2022

View File

@ -69,7 +69,7 @@ class MysqlMutex extends DbMutex
return $this->db->useMaster(function ($db) use ($name, $timeout) {
/** @var \yii\db\Connection $db */
return (bool) $db->createCommand(
'SELECT GET_LOCK(CONCAT(:prefix, :name), :timeout)',
'SELECT GET_LOCK(SUBSTRING(CONCAT(:prefix, :name), 1, 64), :timeout)',
[':name' => $this->hashLockName($name), ':timeout' => $timeout, ':prefix' => $this->keyPrefix]
)->queryScalar();
});
@ -86,7 +86,7 @@ class MysqlMutex extends DbMutex
return $this->db->useMaster(function ($db) use ($name) {
/** @var \yii\db\Connection $db */
return (bool) $db->createCommand(
'SELECT RELEASE_LOCK(CONCAT(:prefix, :name))',
'SELECT RELEASE_LOCK(SUBSTRING(CONCAT(:prefix, :name), 1, 64))',
[':name' => $this->hashLockName($name), ':prefix' => $this->keyPrefix]
)->queryScalar();
});

View File

@ -53,6 +53,22 @@ class MysqlMutexTest extends DatabaseTestCase
$this->assertTrue($mutexTwo->release($mutexName));
}
/**
* @dataProvider mutexDataProvider()
*
* @param string $mutexName
*/
public function testThatMutexLocksWithKeyPrefixesLongString($mutexName)
{
$mutexOne = $this->createMutex(['keyPrefix' => str_repeat('a', 40)]);
$mutexTwo = $this->createMutex(['keyPrefix' => str_repeat('b', 40)]);
$this->assertTrue($mutexOne->acquire($mutexName));
$this->assertTrue($mutexTwo->acquire($mutexName));
$this->assertTrue($mutexOne->release($mutexName));
$this->assertTrue($mutexTwo->release($mutexName));
}
/**
* @dataProvider mutexDataProvider()
*