summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-07-06 14:50:18 +0200
committerGitHub <noreply@github.com>2018-07-06 14:50:18 +0200
commit422c805e260f3187fffe7957b2d2f637e20812e3 (patch)
tree98c007b78eabc4997b7311acc4f6599aecfcbe6f /lib/private
parent3c9b12139e8d6013267d6c2c48d09b0fbf527e34 (diff)
parent3d5acbb1d0944ba00fee9af72f7253e6fc7f787e (diff)
downloadnextcloud-server-422c805e260f3187fffe7957b2d2f637e20812e3.tar.gz
nextcloud-server-422c805e260f3187fffe7957b2d2f637e20812e3.zip
Merge pull request #10116 from nextcloud/lock-negative
prevent lock values from going negative with memcache backend
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Lock/MemcacheLockingProvider.php10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php
index 55a82b22781..4d1b3dc0bca 100644
--- a/lib/private/Lock/MemcacheLockingProvider.php
+++ b/lib/private/Lock/MemcacheLockingProvider.php
@@ -90,14 +90,20 @@ class MemcacheLockingProvider extends AbstractLockingProvider {
*/
public function releaseLock(string $path, int $type) {
if ($type === self::LOCK_SHARED) {
+ $newValue = 0;
if ($this->getOwnSharedLockCount($path) === 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
- $this->memcache->dec($path);
+ $newValue = $this->memcache->dec($path);
}
} else {
// if we own more than one lock ourselves just decrease
- $this->memcache->dec($path);
+ $newValue = $this->memcache->dec($path);
+ }
+
+ // if we somehow release more locks then exists, reset the lock
+ if ($newValue < 0) {
+ $this->memcache->cad($path, $newValue);
}
} else if ($type === self::LOCK_EXCLUSIVE) {
$this->memcache->cad($path, 'exclusive');