mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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 <AndreKurait@gmail.com> Signed-off-by: Andre Kurait <akurait@amazon.com> Signed-off-by: Jackson Price <jxnprice@amazon.com>
This commit is contained in:
1 parent
01564bd94c
commit
9becdfa021
2 files changed
+39
-3
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<Thread> 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";
|
||||
|
||||
Reference in new issue
Block a user