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

[stable19] Fix releasing a shared lock multiple times #21710

Merged
merged 2 commits into from
Jul 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
14 changes: 14 additions & 0 deletions apps/dav/lib/Connector/Sabre/LockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ class LockPlugin extends ServerPlugin {
*/
private $server;

/**
* State of the lock
*
* @var bool
*/
private $isLocked;

/**
* {@inheritdoc}
*/
public function initialize(\Sabre\DAV\Server $server) {
$this->server = $server;
$this->server->on('beforeMethod:*', [$this, 'getLock'], 50);
$this->server->on('afterMethod:*', [$this, 'releaseLock'], 50);
$this->isLocked = false;
}

public function getLock(RequestInterface $request) {
Expand All @@ -67,10 +75,15 @@ public function getLock(RequestInterface $request) {
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}
$this->isLocked = true;
}
}

public function releaseLock(RequestInterface $request) {
// don't try to release the lock if we never locked one
if ($this->isLocked === false) {
return;
}
if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
return;
}
Expand All @@ -81,6 +94,7 @@ public function releaseLock(RequestInterface $request) {
}
if ($node instanceof Node) {
$node->releaseLock(ILockingProvider::LOCK_SHARED);
$this->isLocked = false;
}
}
}
6 changes: 5 additions & 1 deletion lib/private/Lock/MemcacheLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ public function acquireLock(string $path, int $type) {
*/
public function releaseLock(string $path, int $type) {
if ($type === self::LOCK_SHARED) {
$ownSharedLockCount = $this->getOwnSharedLockCount($path);
$newValue = 0;
if ($this->getOwnSharedLockCount($path) === 1) {
if ($ownSharedLockCount === 0) { // if we are not holding the lock, don't try to release it
return;
}
if ($ownSharedLockCount === 1) {
$removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go
if (!$removed) { //someone else also has a shared lock, decrease only
$newValue = $this->memcache->dec($path);
Expand Down