Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-07-05 15:39:10 +0300
committerRobin Appelman <robin@icewind.nl>2018-07-10 18:50:45 +0300
commit1fa611577973efe69a319d8d14a32b09f50dc4ec (patch)
tree1b04cbd75d1e97e169966e4edbec7f7cca5800b7 /lib
parent486dff093453b402324b25a63554fcb10fb18e41 (diff)
prevent lock values from going negative with memcache backend
This can be caused by the code releasing more locks then it acquires, once the lock value becomes negative it's likely that it will never be able to change into an exclusive lock again. Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-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 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');