Fixed: [wopi] add a "graceful period" when removing a lock

This ensure that requests like putFile, which comes in the same time frame, encounter a "document is unlocked" error.
This commit is contained in:
2023-01-19 13:20:10 +01:00
parent 583d7b24ba
commit 4fec18f3aa
2 changed files with 13 additions and 4 deletions

View File

@@ -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

View File

@@ -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");
}
}
/**