diff --git a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentLockManager.php b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentLockManager.php index 30388852b..185256238 100644 --- a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentLockManager.php +++ b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentLockManager.php @@ -21,7 +21,10 @@ class ChillDocumentLockManager implements DocumentLockManagerInterface { private const LOCK_DURATION = 60 * 30; - private int $postDeleteLockDurationMs; + /** + * Number of seconds to keep the lock after the delete lock operation + */ + private const LOCK_GRACEFUL_DURATION_TIME = 3; private ChillRedis $redis; @@ -32,9 +35,13 @@ class ChillDocumentLockManager implements DocumentLockManagerInterface public function deleteLock(Document $document, RequestInterface $request): bool { - $this->redis->del($this->getCacheId($document)); + if (0 === $this->redis->exists($this->getCacheId($document))) { + return true; + } - return true; + // some queries (ex.: putFile) may be executed on the same time than the unlock, so + // we add a delay before unlocking the file, instead of deleting it immediatly + return $this->redis->expire($this->getCacheId($document), self::LOCK_GRACEFUL_DURATION_TIME); } public function getLock(Document $document, RequestInterface $request): string diff --git a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php index 8b6e3f846..7eb738469 100644 --- a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php +++ b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php @@ -87,7 +87,9 @@ final class ChillDocumentManager implements DocumentManagerInterface public function deleteLock(Document $document): void { - $this->documentLockManager->deleteLock($document, $this->request); + if (false ===$this->documentLockManager->deleteLock($document, $this->request)) { + throw new \RuntimeException("could not remove the lock"); + } } /**