From 4f1816e03db00219bc2e723e3048848aef7f8fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 23 Oct 2024 11:56:22 +0200 Subject: [PATCH] fix(core): Fix race condition when resolving post-execute promise (#11360) --- packages/cli/src/__tests__/active-executions.test.ts | 9 +++++++++ packages/cli/src/active-executions.ts | 1 + 2 files changed, 10 insertions(+) diff --git a/packages/cli/src/__tests__/active-executions.test.ts b/packages/cli/src/__tests__/active-executions.test.ts index a8c7b0f18e..5432bf5c4a 100644 --- a/packages/cli/src/__tests__/active-executions.test.ts +++ b/packages/cli/src/__tests__/active-executions.test.ts @@ -108,6 +108,15 @@ describe('ActiveExecutions', () => { expect(activeExecutions.getActiveExecutions().length).toBe(0); }); + test('Should not try to resolve a post-execute promise for an inactive execution', async () => { + // @ts-expect-error Private method + const getExecutionSpy = jest.spyOn(activeExecutions, 'getExecution'); + + activeExecutions.finalizeExecution('inactive-execution-id', mockFullRunData()); + + expect(getExecutionSpy).not.toHaveBeenCalled(); + }); + test('Should resolve post execute promise on removal', async () => { const newExecution = mockExecutionData(); const executionId = await activeExecutions.add(newExecution); diff --git a/packages/cli/src/active-executions.ts b/packages/cli/src/active-executions.ts index f5835ca164..bc18eade16 100644 --- a/packages/cli/src/active-executions.ts +++ b/packages/cli/src/active-executions.ts @@ -154,6 +154,7 @@ export class ActiveExecutions { /** Resolve the post-execution promise in an execution. */ finalizeExecution(executionId: string, fullRunData?: IRun) { + if (!this.has(executionId)) return; const execution = this.getExecution(executionId); execution.postExecutePromise.resolve(fullRunData); this.logger.debug('Execution finalized', { executionId });