From 9becdfa0212d9dd76172e733add6a031db0359f3 Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:18:07 -0600 Subject: [PATCH] fix(codepipeline): skip queued actions after an execution stops (#9679) Check for a stop request when the worker acquires the execution lock to register its action. A queued action can otherwise register after stop has already visited the action list and then invoke its provider. Adapted from Andre Kurait's CodePipeline action admission change in 5fe030e5dd4713bfdd2efbfb49f7dc6664ec8008. Co-authored-by: Andre Kurait Signed-off-by: Andre Kurait Signed-off-by: Jackson Price --- .../codepipeline/CodePipelineService.java | 7 ++-- .../codepipeline/CodePipelineServiceTest.java | 35 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/floci/aws/services/codepipeline/CodePipelineService.java b/src/main/java/io/floci/aws/services/codepipeline/CodePipelineService.java index 9d6fae12ea..e51de9d694 100644 --- a/src/main/java/io/floci/aws/services/codepipeline/CodePipelineService.java +++ b/src/main/java/io/floci/aws/services/codepipeline/CodePipelineService.java @@ -2073,8 +2073,8 @@ public class CodePipelineService implements StoredResourceArns { return !"Succeeded".equals(previousStatuses.get(action.path("name").asText())); } - private void runAction(CodePipelinePipeline pipeline, CodePipelineExecution execution, - String stageName, JsonNode action) { + void runAction(CodePipelinePipeline pipeline, CodePipelineExecution execution, + String stageName, JsonNode action) { ActionExecution state = new ActionExecution(); state.setActionExecutionId(UUID.randomUUID().toString()); state.setStageName(stageName); @@ -2088,6 +2088,9 @@ public class CodePipelineService implements StoredResourceArns { state.setStartTime(now()); state.setLastUpdateTime(state.getStartTime()); synchronized (execution) { + if (execution.isStopRequested()) { + return; + } execution.getActionExecutions().add(state); putExecution(execution); } diff --git a/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java b/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java index 2593835f60..562908c5fe 100644 --- a/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java +++ b/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java @@ -75,12 +75,13 @@ class CodePipelineServiceTest { private final ObjectMapper mapper = new ObjectMapper(); private final CapturingStorageFactory storage = new CapturingStorageFactory(); + private final LambdaService lambdaService = mock(LambdaService.class); private final CodePipelineService service = new CodePipelineService( storage, mapper, mock(CodeBuildService.class), mock(CodeDeployService.class), - mock(LambdaService.class), + lambdaService, mock(S3Service.class), configWithPollInterval(500L)); @Test @@ -1604,6 +1605,38 @@ class CodePipelineServiceTest { } } + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void queuedActionCannotRegisterAfterStopHasTraversedTheExecution(boolean abandon) throws Exception { + String pipeline = "stop-before-action-admission"; + String executionId = "queued-execution"; + try (ExecutorService workers = Executors.newSingleThreadExecutor()) { + JsonNode action = mapper.readTree(""" + {"name":"Invoke","actionTypeId":{"category":"Invoke","owner":"AWS","provider":"Lambda","version":"1"}, + "configuration":{"FunctionName":"function"}} + """); + createExternalActionPipeline(service, pipeline, action.toString()); + CodePipelineExecution execution = waitingExecution(storage, pipeline, executionId, 1, "External"); + AtomicReference worker = new AtomicReference<>(); + Future queued; + synchronized (execution) { + queued = workers.submit(() -> { + worker.set(Thread.currentThread()); + service.runAction(new CodePipelinePipeline(), execution, "External", action); + }); + ThreadStates.awaitBlockedOrDone(worker, queued); + assertFalse(queued.isDone()); + stopExecution(service, pipeline, executionId, abandon); + } + queued.get(5, TimeUnit.SECONDS); + assertTrue(execution.getActionExecutions().isEmpty(), "No provider may be admitted after stop"); + assertEquals("Stopping", execution.getStatus()); + verify(lambdaService, never()).invoke(anyString(), anyString(), any(), any()); + } finally { + service.shutdown(); + } + } + @Test void listActionsIncludesAnActionRegisteredWhileTheRequestWaits() throws Exception { String pipeline = "list-during-action-registration";