Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Check if an array lock exists before releasing it #31795

Merged
merged 1 commit into from
Mar 6, 2020
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
Check if lock exists before releasing it.
  • Loading branch information
paulandroshchuk committed Mar 6, 2020
commit edd4d884ccfa7a9fc5123acc91b31e85abc3b980
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());
}
}