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

[10.x] Fix race condition in locks issued by the file cache driver #43686

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/Illuminate/Cache/CacheLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CacheLock extends Lock
/**
* Create a new lock instance.
*
* @param \Illuminate\Contracts\Cache\Store $store
* @param \Illuminate\Contracts\Cache\Store $store The store must contain an add method that atomically stores an item in the cache if it does not already exist. See CacheLock's acquire method for details.
* @param string $name
* @param int $seconds
* @param string|null $owner
Expand All @@ -34,19 +34,9 @@ public function __construct($store, $name, $seconds, $owner = null)
*/
public function acquire()
{
if (method_exists($this->store, 'add') && $this->seconds > 0) {
return $this->store->add(
$this->name, $this->owner, $this->seconds
);
}

if (! is_null($this->store->get($this->name))) {
return false;
}

return ($this->seconds > 0)
? $this->store->put($this->name, $this->owner, $this->seconds)
: $this->store->forever($this->name, $this->owner);
return $this->store->add(
$this->name, $this->owner, $this->seconds
);
}

/**
Expand Down