Skip to content

Commit

Permalink
Check if lock exists before releasing it. (#31795)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulandroshchuk authored Mar 6, 2020
1 parent fa901c3 commit 2460f09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Cache/ArrayLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ protected function exists()
*/
public function release()
{
if (! $this->exists()) {
return false;
}

if (! $this->isOwnedByCurrentProcess()) {
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Cache/CacheArrayStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,15 @@ public function testAnotherOwnerCanForceReleaseALock()

$this->assertTrue($wannabeOwner->acquire());
}

public function testReleasingLockAfterAlreadyForceReleasedByAnotherOwnerFails()
{
$store = new ArrayStore;
$owner = $store->lock('foo', 10);
$wannabeOwner = $store->lock('foo', 10);
$owner->acquire();
$wannabeOwner->forceRelease();

$this->assertFalse($wannabeOwner->release());
}
}

0 comments on commit 2460f09

Please sign in to comment.