Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,14 @@
<PropertyNotSetInConstructor>
<code><![CDATA[$coroutine]]></code>
</PropertyNotSetInConstructor>
<RedundantCondition>
<code><![CDATA[$this->context?->destroy()]]></code>
<code><![CDATA[$this->scopeContext?->destroy()]]></code>
</RedundantCondition>
<TypeDoesNotContainNull>
<code><![CDATA[$this->context]]></code>
<code><![CDATA[$this->scopeContext]]></code>
</TypeDoesNotContainNull>
<UndefinedInterfaceMethod>
<code><![CDATA[catch]]></code>
<code><![CDATA[finally]]></code>
Expand Down
5 changes: 4 additions & 1 deletion src/Internal/Transport/Router/DestroyWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Temporal\Internal\Support\GarbageCollector;
use Temporal\Internal\Workflow\Process\Process;
use Temporal\Internal\Workflow\ProcessCollection;
use Temporal\Worker\FeatureFlags;
use Temporal\Worker\LoopInterface;
use Temporal\Worker\Transport\Command\ServerRequestInterface;

Expand All @@ -29,12 +30,14 @@ class DestroyWorkflow extends WorkflowProcessAwareRoute
private const GC_TIMEOUT_SECONDS = 30;

private GarbageCollector $gc;
private bool $throwDestructException;

public function __construct(
ProcessCollection $running,
protected LoopInterface $loop,
) {
$this->gc = new GarbageCollector(self::GC_THRESHOLD, self::GC_TIMEOUT_SECONDS);
$this->throwDestructException = FeatureFlags::$throwDestructMemorizedInstanceException;
parent::__construct($running);
}

Expand All @@ -51,7 +54,7 @@ public function kill(string $runId): array
$process = $this->running
->pull($runId, "Unable to kill workflow because workflow process #$runId was not found");

$process->cancel(new DestructMemorizedInstanceException());
$this->throwDestructException and $process->cancel(new DestructMemorizedInstanceException());
$this->loop->once(
LoopInterface::ON_FINALLY,
function () use ($process): void {
Expand Down
13 changes: 10 additions & 3 deletions src/Internal/Workflow/Process/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,16 @@ public function onAwait(Deferred $deferred): void

public function destroy(): void
{
$this->scopeContext->destroy();
$this->context->destroy();
unset($this->coroutine);
$this->context?->destroy();
$this->scopeContext?->destroy();
unset(
$this->context,
$this->scopeContext,
$this->deferred,
$this->services,
$this->onCancel,
$this->onClose,
);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Worker/FeatureFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Temporal\Worker;

use Temporal\Exception\DestructMemorizedInstanceException;
use Temporal\Workflow;

/**
Expand Down Expand Up @@ -48,4 +49,11 @@ final class FeatureFlags
* @since SDK 2.16.0
*/
public static bool $cancelAbandonedChildWorkflows = true;

/**
* Throw {@see DestructMemorizedInstanceException} when a Workflow instance is destructed.
*
* @since SDK 2.16.0
*/
public static bool $throwDestructMemorizedInstanceException = true;
}
Loading