Skip to content

Commit

Permalink
Fix Expiring lock in PDO and ZooKeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Jun 17, 2019
1 parent 953ac3e commit d1ed1d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Symfony/Component/Lock/Store/PdoStore.php
Expand Up @@ -16,7 +16,6 @@
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;
Expand All @@ -36,6 +35,8 @@
*/
class PdoStore implements StoreInterface
{
use ExpiringStoreTrait;

private $conn;
private $dsn;
private $driver;
Expand Down Expand Up @@ -123,9 +124,7 @@ public function save(Key $key)

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) {
Expand All @@ -136,13 +135,11 @@ public function save(Key $key)
$this->putOffExpiration($key, $this->initialTtl);
}

if ($key->isExpired()) {
throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $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);
}

/**
Expand Down Expand Up @@ -178,9 +175,7 @@ public function putOffExpiration(Key $key, $ttl)
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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Lock/Store/ZookeeperStore.php
Expand Up @@ -25,6 +25,8 @@
*/
class ZookeeperStore implements StoreInterface
{
use ExpiringStoreTrait;

private $zookeeper;

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

$this->createNewLock($resource, $token);

$this->checkNotExpired($key);
}

/**
Expand Down

0 comments on commit d1ed1d2

Please sign in to comment.