Do not wait until Lock acquiry but a configurable amount of time (30s per default)

This commit is contained in:
Ferdinand Kuhl 2022-05-16 11:28:39 +02:00
parent a5ce21d554
commit ec13bc4960
2 changed files with 20 additions and 3 deletions

View file

@ -8,6 +8,7 @@ use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Component\ComponentContext; use Neos\Flow\Http\Component\ComponentContext;
use Neos\Flow\Http\Component\ComponentInterface; use Neos\Flow\Http\Component\ComponentInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\Lock\Exception\LockAcquiringException;
use Symfony\Component\Lock\Key; use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\LockFactory;
@ -45,6 +46,12 @@ class SessionLockRequestComponent implements ComponentInterface
*/ */
protected bool $autoRelease; protected bool $autoRelease;
/**
* @Flow\InjectConfiguration(package="DigiComp.FlowSessionLock", path="secondsToWait")
* @var int
*/
protected int $secondsToWait;
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -64,8 +71,17 @@ class SessionLockRequestComponent implements ComponentInterface
$componentContext->setParameter(SessionLockRequestComponent::class, static::PARAMETER_NAME, $lock); $componentContext->setParameter(SessionLockRequestComponent::class, static::PARAMETER_NAME, $lock);
$this->logger->debug('SessionLock: Get ' . $key); $this->logger->debug('SessionLock: Try to get "' . $key . '"');
$lock->acquire(true); $timedOut = \time() + $this->secondsToWait;
$this->logger->debug('SessionLock: Acquired ' . $key); while (!$lock->acquire() || $timedOut <= \time()) {
\usleep(100000);
}
if (!$lock->isAcquired()) {
throw new LockAcquiringException(
'Could not acquire the lock for "' . $key . '" in ' . $this->secondsToWait . ' seconds.',
1652687960
);
}
$this->logger->debug('SessionLock: Acquired "' . $key . '"');
} }
} }

View file

@ -3,6 +3,7 @@ DigiComp:
lockStoreConnection: "flock://%FLOW_PATH_DATA%Temporary/Production/SessionLocks/" lockStoreConnection: "flock://%FLOW_PATH_DATA%Temporary/Production/SessionLocks/"
timeToLive: 300.0 timeToLive: 300.0
autoRelease: true autoRelease: true
secondsToWait: 30
readOnlyExpressions: {} readOnlyExpressions: {}
Neos: Neos: