diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-07-11 09:02:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-11 09:02:19 +0200 |
commit | 922c2c64b5d9a9f9ba8d7aa1f7c79a788875b7d6 (patch) | |
tree | b8ef9d4fb65997eef9e4f21ac75f4ece4080cf12 /lib | |
parent | ef1a6957079395053cad24d6994ee634c6596c67 (diff) | |
parent | 1fa611577973efe69a319d8d14a32b09f50dc4ec (diff) | |
download | nextcloud-server-922c2c64b5d9a9f9ba8d7aa1f7c79a788875b7d6.tar.gz nextcloud-server-922c2c64b5d9a9f9ba8d7aa1f7c79a788875b7d6.zip |
Merge pull request #10180 from nextcloud/lock-negative-13
[13] prevent lock values from going negative with memcache backend
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Lock/MemcacheLockingProvider.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php index ddd73aec095..893010fdf1e 100644 --- a/lib/private/Lock/MemcacheLockingProvider.php +++ b/lib/private/Lock/MemcacheLockingProvider.php @@ -89,14 +89,20 @@ class MemcacheLockingProvider extends AbstractLockingProvider { */ public function releaseLock($path, $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'); |