diff --git a/src/OrchestrationContext.php b/src/OrchestrationContext.php index 052c6739..ad8a1b0a 100644 --- a/src/OrchestrationContext.php +++ b/src/OrchestrationContext.php @@ -313,6 +313,7 @@ function(Event $event, string $eventIdentity) use ($identity) { ) ); } + $this->history->locks = []; }); } diff --git a/src/State/OrchestrationHistory.php b/src/State/OrchestrationHistory.php index acdb18d5..19211e84 100644 --- a/src/State/OrchestrationHistory.php +++ b/src/State/OrchestrationHistory.php @@ -35,6 +35,8 @@ use Bottledcode\DurablePhp\Events\StartOrchestration; use Bottledcode\DurablePhp\Events\TaskCompleted; use Bottledcode\DurablePhp\Events\TaskFailed; +use Bottledcode\DurablePhp\Events\WithEntity; +use Bottledcode\DurablePhp\Events\WithLock; use Bottledcode\DurablePhp\Events\WithOrchestration; use Bottledcode\DurablePhp\Exceptions\ExternalException; use Bottledcode\DurablePhp\Exceptions\Unwind; @@ -179,6 +181,16 @@ private function construct(): \Generator $e->getTraceAsString(), $e::class ); + } finally { + if (!$this->isRunning()) { + // ok, we now need to release all of the locks that we have + foreach ($this->locks as $lock) { + yield WithLock::onEntity( + $this->id, + WithEntity::forInstance($lock, RaiseEvent::forUnlock($this->id->id, null, null)) + ); + } + } } $completion = WithOrchestration::forInstance(StateId::fromInstance($this->instance), $completion);