From 432c21f83c5c5ca32ff3b98085dfe0aeb8bcd67e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 17 Jun 2019 20:45:27 +0200 Subject: [PATCH 1/3] [Lock] fix bad merge --- src/Symfony/Component/Lock/Store/PdoStore.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Lock/Store/PdoStore.php b/src/Symfony/Component/Lock/Store/PdoStore.php index 8066501166..3b5049f84d 100644 --- a/src/Symfony/Component/Lock/Store/PdoStore.php +++ b/src/Symfony/Component/Lock/Store/PdoStore.php @@ -16,7 +16,6 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\Schema; use Symfony\Component\Lock\Exception\InvalidArgumentException; use Symfony\Component\Lock\Exception\LockConflictedException; -use Symfony\Component\Lock\Exception\LockExpiredException; use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\StoreInterface; @@ -36,6 +35,8 @@ use Symfony\Component\Lock\StoreInterface; */ class PdoStore implements StoreInterface { + use ExpiringStoreTrait; + private $conn; private $dsn; private $driver; @@ -123,9 +124,7 @@ class PdoStore implements StoreInterface try { $stmt->execute(); - if ($key->isExpired()) { - throw new LockExpiredException(sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $key)); - } + $this->checkNotExpired($key); return; } catch (DBALException $e) { @@ -136,9 +135,7 @@ class PdoStore implements StoreInterface $this->putOffExpiration($key, $this->initialTtl); } - if ($key->isExpired()) { - throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $key)); - } + $this->checkNotExpired($key); if ($this->gcProbability > 0 && (1.0 === $this->gcProbability || (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) <= $this->gcProbability)) { $this->prune(); @@ -178,9 +175,7 @@ class PdoStore implements StoreInterface throw new LockConflictedException(); } - if ($key->isExpired()) { - throw new LockExpiredException(sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $key)); - } + $this->checkNotExpired($key); } /** From 4f808ef4f4c77abaed9be31d4230ead832c609b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 17 Jun 2019 20:41:36 +0200 Subject: [PATCH 2/3] Fix Expiring lock in PDO and ZooKeeper --- src/Symfony/Component/Lock/Store/ZookeeperStore.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/Lock/Store/ZookeeperStore.php b/src/Symfony/Component/Lock/Store/ZookeeperStore.php index 4f8b4ee374..ce3cb4bab7 100644 --- a/src/Symfony/Component/Lock/Store/ZookeeperStore.php +++ b/src/Symfony/Component/Lock/Store/ZookeeperStore.php @@ -25,6 +25,8 @@ use Symfony\Component\Lock\StoreInterface; */ class ZookeeperStore implements StoreInterface { + use ExpiringStoreTrait; + private $zookeeper; public function __construct(\Zookeeper $zookeeper) @@ -45,6 +47,8 @@ class ZookeeperStore implements StoreInterface $token = $this->getUniqueToken($key); $this->createNewLock($resource, $token); + + $this->checkNotExpired($key); } /** From fc2dc1492446ed2fb8018d3fbf8cb42837003ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 17 Jun 2019 20:49:50 +0200 Subject: [PATCH 3/3] Fix PDO prune not called --- src/Symfony/Component/Lock/Store/PdoStore.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Lock/Store/PdoStore.php b/src/Symfony/Component/Lock/Store/PdoStore.php index 3b5049f84d..0cf3dd35f7 100644 --- a/src/Symfony/Component/Lock/Store/PdoStore.php +++ b/src/Symfony/Component/Lock/Store/PdoStore.php @@ -124,9 +124,6 @@ class PdoStore implements StoreInterface try { $stmt->execute(); - $this->checkNotExpired($key); - - return; } catch (DBALException $e) { // the lock is already acquired. It could be us. Let's try to put off. $this->putOffExpiration($key, $this->initialTtl); @@ -135,11 +132,11 @@ class PdoStore implements StoreInterface $this->putOffExpiration($key, $this->initialTtl); } - $this->checkNotExpired($key); - if ($this->gcProbability > 0 && (1.0 === $this->gcProbability || (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) <= $this->gcProbability)) { $this->prune(); } + + $this->checkNotExpired($key); } /** @@ -289,7 +286,7 @@ class PdoStore implements StoreInterface } /** - * Cleanups the table by removing all expired locks. + * Cleans up the table by removing all expired locks. */ private function prune(): void {