Skip to content

Commit 760d73d

Browse files
fix: disable ALS stores when no longer needed
1 parent 29e177b commit 760d73d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

packages/worker/src/workflow/reusable-vm.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,15 @@ export class ReusableVMWorkflowCreator implements WorkflowCreator {
210210
* Cleanup the pre-compiled script
211211
*/
212212
public async destroy(): Promise<void> {
213-
// TODO: disable AsyncLocalStorage used for cancellation/update scopes
213+
if (this._context) {
214+
vm.runInContext(
215+
`{
216+
__TEMPORAL__.api.destroy();
217+
}`,
218+
this._context,
219+
{ timeout: this.isolateExecutionTimeoutMs, displayErrors: true }
220+
);
221+
}
214222
globalHandlers.removeWorkflowBundle(this.workflowBundle);
215223
delete this._context;
216224
}

packages/worker/src/workflow/vm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class VMWorkflowCreator implements WorkflowCreator {
126126
export class VMWorkflow extends BaseVMWorkflow {
127127
public async dispose(): Promise<void> {
128128
this.workflowModule.dispose();
129+
this.workflowModule.destroy();
129130
VMWorkflowCreator.workflowByRunId.delete(this.runId);
130131
delete this.context;
131132
}

packages/workflow/src/worker-interface.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { WorkflowInterceptorsFactory } from './interceptors';
1010
import { WorkflowCreateOptionsInternal } from './interfaces';
1111
import { Activator } from './internals';
1212
import { setActivatorUntyped, getActivator } from './global-attributes';
13+
import { disableStorage } from './cancellation-scope';
14+
import { disableUpdateStorage } from './update-scope';
1315

1416
// Export the type for use on the "worker" side
1517
export { PromiseStackStore } from './internals';
@@ -261,6 +263,11 @@ export function dispose(): void {
261263
}
262264
}
263265

266+
export function destroy(): void {
267+
disableStorage();
268+
disableUpdateStorage();
269+
}
270+
264271
function isWorkflowFunctionWithOptions(obj: any): obj is WorkflowFunctionWithOptions<any[], any> {
265272
if (obj == null) return false;
266273
return Object.hasOwn(obj, 'workflowDefinitionOptions');

0 commit comments

Comments
 (0)