Skip to content

Commit d1ed1d2

Browse files
committed
Fix Expiring lock in PDO and ZooKeeper
1 parent 953ac3e commit d1ed1d2

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/Symfony/Component/Lock/Store/PdoStore.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Doctrine\DBAL\Schema\Schema;
1717
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1818
use Symfony\Component\Lock\Exception\LockConflictedException;
19-
use Symfony\Component\Lock\Exception\LockExpiredException;
2019
use Symfony\Component\Lock\Exception\NotSupportedException;
2120
use Symfony\Component\Lock\Key;
2221
use Symfony\Component\Lock\StoreInterface;
@@ -36,6 +35,8 @@
3635
*/
3736
class PdoStore implements StoreInterface
3837
{
38+
use ExpiringStoreTrait;
39+
3940
private $conn;
4041
private $dsn;
4142
private $driver;
@@ -123,9 +124,7 @@ public function save(Key $key)
123124

124125
try {
125126
$stmt->execute();
126-
if ($key->isExpired()) {
127-
throw new LockExpiredException(sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $key));
128-
}
127+
$this->checkNotExpired($key);
129128

130129
return;
131130
} catch (DBALException $e) {
@@ -136,13 +135,11 @@ public function save(Key $key)
136135
$this->putOffExpiration($key, $this->initialTtl);
137136
}
138137

139-
if ($key->isExpired()) {
140-
throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $key));
141-
}
142-
143138
if ($this->gcProbability > 0 && (1.0 === $this->gcProbability || (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) <= $this->gcProbability)) {
144139
$this->prune();
145140
}
141+
142+
$this->checkNotExpired($key);
146143
}
147144

148145
/**
@@ -178,9 +175,7 @@ public function putOffExpiration(Key $key, $ttl)
178175
throw new LockConflictedException();
179176
}
180177

181-
if ($key->isExpired()) {
182-
throw new LockExpiredException(sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $key));
183-
}
178+
$this->checkNotExpired($key);
184179
}
185180

186181
/**

src/Symfony/Component/Lock/Store/ZookeeperStore.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class ZookeeperStore implements StoreInterface
2727
{
28+
use ExpiringStoreTrait;
29+
2830
private $zookeeper;
2931

3032
public function __construct(\Zookeeper $zookeeper)
@@ -45,6 +47,8 @@ public function save(Key $key)
4547
$token = $this->getUniqueToken($key);
4648

4749
$this->createNewLock($resource, $token);
50+
51+
$this->checkNotExpired($key);
4852
}
4953

5054
/**

0 commit comments

Comments
 (0)