diff --git a/Classes/Http/SessionLockRequestComponent.php b/Classes/Http/SessionLockRequestComponent.php index aa0b45e..97a6da4 100644 --- a/Classes/Http/SessionLockRequestComponent.php +++ b/Classes/Http/SessionLockRequestComponent.php @@ -8,6 +8,7 @@ use Neos\Flow\Annotations as Flow; use Neos\Flow\Http\Component\ComponentContext; use Neos\Flow\Http\Component\ComponentInterface; use Psr\Log\LoggerInterface; +use Symfony\Component\Lock\Exception\LockAcquiringException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\LockFactory; @@ -45,6 +46,12 @@ class SessionLockRequestComponent implements ComponentInterface */ protected bool $autoRelease; + /** + * @Flow\InjectConfiguration(package="DigiComp.FlowSessionLock", path="secondsToWait") + * @var int + */ + protected int $secondsToWait; + /** * @inheritDoc */ @@ -64,8 +71,17 @@ class SessionLockRequestComponent implements ComponentInterface $componentContext->setParameter(SessionLockRequestComponent::class, static::PARAMETER_NAME, $lock); - $this->logger->debug('SessionLock: Get ' . $key); - $lock->acquire(true); - $this->logger->debug('SessionLock: Acquired ' . $key); + $this->logger->debug('SessionLock: Try to get "' . $key . '"'); + $timedOut = \time() + $this->secondsToWait; + 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 . '"'); } } diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index f5b77b2..f283d84 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -3,6 +3,7 @@ DigiComp: lockStoreConnection: "flock://%FLOW_PATH_DATA%Temporary/Production/SessionLocks/" timeToLive: 300.0 autoRelease: true + secondsToWait: 30 readOnlyExpressions: {} Neos: