Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/Symfony/Component/Lock/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,22 @@ public function isAcquired()
*/
public function release()
{
$this->store->delete($this->key);
$this->dirty = false;
try {
try {
$this->store->delete($this->key);
$this->dirty = false;
} catch (LockReleasingException $e) {
throw $e;
} catch (\Exception $e) {
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key), 0, $e);
}

if ($this->store->exists($this->key)) {
if ($this->store->exists($this->key)) {
throw new LockReleasingException(sprintf('Failed to release the "%s" lock, the resource is still locked.', $this->key));
}
} catch (LockReleasingException $e) {
$this->logger->notice('Failed to release the "{resource}" lock.', array('resource' => $this->key));
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key));
throw $e;
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Component/Lock/Tests/LockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ public function testNoAutoReleaseWhenNotConfigured()
unset($lock);
}

/**
* @expectedException \Symfony\Component\Lock\Exception\LockReleasingException
*/
public function testReleaseThrowsExceptionWhenDeletionFail()
{
$key = new Key(uniqid(__METHOD__, true));
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
$lock = new Lock($key, $store, 10);

$store
->expects($this->once())
->method('delete')
->with($key)
->willThrowException(new \RuntimeException('Boom'));

$store
->expects($this->never())
->method('exists')
->with($key);

$lock->release();
}

/**
* @expectedException \Symfony\Component\Lock\Exception\LockReleasingException
*/
Expand Down