Skip to content

Commit 8dcc518

Browse files
authored
Merge pull request #651: Add feature flag throwDestructMemorizedInstanceException
2 parents ffabfef + 5605bcd commit 8dcc518

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

psalm-baseline.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,14 @@
11711171
<PropertyNotSetInConstructor>
11721172
<code><![CDATA[$coroutine]]></code>
11731173
</PropertyNotSetInConstructor>
1174+
<RedundantCondition>
1175+
<code><![CDATA[$this->context?->destroy()]]></code>
1176+
<code><![CDATA[$this->scopeContext?->destroy()]]></code>
1177+
</RedundantCondition>
1178+
<TypeDoesNotContainNull>
1179+
<code><![CDATA[$this->context]]></code>
1180+
<code><![CDATA[$this->scopeContext]]></code>
1181+
</TypeDoesNotContainNull>
11741182
<UndefinedInterfaceMethod>
11751183
<code><![CDATA[catch]]></code>
11761184
<code><![CDATA[finally]]></code>

src/Internal/Transport/Router/DestroyWorkflow.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Temporal\Internal\Support\GarbageCollector;
1818
use Temporal\Internal\Workflow\Process\Process;
1919
use Temporal\Internal\Workflow\ProcessCollection;
20+
use Temporal\Worker\FeatureFlags;
2021
use Temporal\Worker\LoopInterface;
2122
use Temporal\Worker\Transport\Command\ServerRequestInterface;
2223

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

3132
private GarbageCollector $gc;
33+
private bool $throwDestructException;
3234

3335
public function __construct(
3436
ProcessCollection $running,
3537
protected LoopInterface $loop,
3638
) {
3739
$this->gc = new GarbageCollector(self::GC_THRESHOLD, self::GC_TIMEOUT_SECONDS);
40+
$this->throwDestructException = FeatureFlags::$throwDestructMemorizedInstanceException;
3841
parent::__construct($running);
3942
}
4043

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

54-
$process->cancel(new DestructMemorizedInstanceException());
57+
$this->throwDestructException and $process->cancel(new DestructMemorizedInstanceException());
5558
$this->loop->once(
5659
LoopInterface::ON_FINALLY,
5760
function () use ($process): void {

src/Internal/Workflow/Process/Scope.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,16 @@ public function onAwait(Deferred $deferred): void
293293

294294
public function destroy(): void
295295
{
296-
$this->scopeContext->destroy();
297-
$this->context->destroy();
298-
unset($this->coroutine);
296+
$this->context?->destroy();
297+
$this->scopeContext?->destroy();
298+
unset(
299+
$this->context,
300+
$this->scopeContext,
301+
$this->deferred,
302+
$this->services,
303+
$this->onCancel,
304+
$this->onClose,
305+
);
299306
}
300307

301308
/**

src/Worker/FeatureFlags.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Temporal\Worker;
66

7+
use Temporal\Exception\DestructMemorizedInstanceException;
78
use Temporal\Workflow;
89

910
/**
@@ -48,4 +49,11 @@ final class FeatureFlags
4849
* @since SDK 2.16.0
4950
*/
5051
public static bool $cancelAbandonedChildWorkflows = true;
52+
53+
/**
54+
* Throw {@see DestructMemorizedInstanceException} when a Workflow instance is destructed.
55+
*
56+
* @since SDK 2.16.0
57+
*/
58+
public static bool $throwDestructMemorizedInstanceException = true;
5159
}

0 commit comments

Comments
 (0)