]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix releasing a shared lock multiple times
authorJaakko Salo <jaakkos@gmail.com>
Sun, 24 May 2020 00:19:04 +0000 (03:19 +0300)
committerJaakko Salo <jaakko@meetiqm.com>
Sun, 24 May 2020 17:23:57 +0000 (20:23 +0300)
Signed-off-by: Jaakko Salo <jaakkos@gmail.com>
lib/private/Lock/MemcacheLockingProvider.php

index 3d7510f43ffd015b36e2b90ecad835718e1cd9c5..bff4eabbbd8208cdddecc69e80b0455e92ff4b8a 100644 (file)
@@ -94,8 +94,12 @@ class MemcacheLockingProvider extends AbstractLockingProvider {
         */
        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);