mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(codepipeline): synchronize action abandonment with registration (#7634)
StopPipelineExecution traversed the action list while a worker could append to it under the execution monitor. Use the same monitor for abandonment so a concurrent registration cannot invalidate the traversal. Add a deterministic public-handler regression that registers an action while the stop waits and verifies that only in-progress actions are abandoned. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> Signed-off-by: Jackson Price <jxnprice@amazon.com>
This commit is contained in:
1 parent
cf96dadfd9
commit
cdcb79a832
2 files changed
+55
-6
No files matched your search
+8
-6
@@ -660,12 +660,14 @@ public class CodePipelineService {
|
||||
execution.getStageExecutionStatuses().put(execution.getCurrentStage(), "Stopping");
|
||||
}
|
||||
if (execution.isAbandon()) {
|
||||
execution.getActionExecutions().stream()
|
||||
.filter(a -> "InProgress".equals(a.getStatus()))
|
||||
.forEach(a -> {
|
||||
a.setStatus("Abandoned");
|
||||
a.setLastUpdateTime(now());
|
||||
});
|
||||
synchronized (execution) {
|
||||
execution.getActionExecutions().stream()
|
||||
.filter(a -> "InProgress".equals(a.getStatus()))
|
||||
.forEach(a -> {
|
||||
a.setStatus("Abandoned");
|
||||
a.setLastUpdateTime(now());
|
||||
});
|
||||
}
|
||||
}
|
||||
putExecution(execution);
|
||||
eventPublisher.pipelineStateChange(execution, "STOPPING");
|
||||
|
||||
+47
@@ -13,11 +13,13 @@ import io.github.hectorvent.floci.services.codebuild.model.Build;
|
||||
import io.github.hectorvent.floci.services.codedeploy.CodeDeployService;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.Deployment;
|
||||
import io.github.hectorvent.floci.services.codepipeline.model.CodePipelineExecution;
|
||||
import io.github.hectorvent.floci.services.codepipeline.model.CodePipelineExecution.ActionExecution;
|
||||
import io.github.hectorvent.floci.services.codepipeline.model.CodePipelinePipeline;
|
||||
import io.github.hectorvent.floci.services.codepipeline.model.CodePipelinePipeline.TransitionState;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import io.github.hectorvent.floci.testing.ThreadStates;
|
||||
import io.smallrye.config.SmallRyeConfigBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -31,6 +33,9 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -1127,6 +1132,48 @@ class CodePipelineServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void abandonIncludesAnActionRegisteredWhileTheStopWaits() throws Exception {
|
||||
String pipeline = "abandon-during-action-registration";
|
||||
String executionId = "registering-execution";
|
||||
try (ExecutorService requests = Executors.newSingleThreadExecutor()) {
|
||||
createExternalActionPipeline(service, pipeline, """
|
||||
{"name":"Approve","actionTypeId":{
|
||||
"category":"Approval","owner":"AWS","provider":"Manual","version":"1"}}
|
||||
""");
|
||||
CodePipelineExecution execution = waitingExecution(storage, pipeline, executionId, 1, "External");
|
||||
ActionExecution completed = new ActionExecution();
|
||||
completed.setStatus("Succeeded");
|
||||
execution.getActionExecutions().add(completed);
|
||||
ActionExecution registering = new ActionExecution();
|
||||
registering.setStatus("InProgress");
|
||||
AtomicReference<Thread> stoppingThread = new AtomicReference<>();
|
||||
Future<JsonNode> stopped;
|
||||
synchronized (execution) {
|
||||
stopped = requests.submit(() -> {
|
||||
stoppingThread.set(Thread.currentThread());
|
||||
return handle("StopPipelineExecution", """
|
||||
{
|
||||
"pipelineName": "%s",
|
||||
"pipelineExecutionId": "%s",
|
||||
"abandon": true
|
||||
}
|
||||
""".formatted(pipeline, executionId));
|
||||
});
|
||||
ThreadStates.awaitBlockedOrDone(stoppingThread, stopped);
|
||||
// The worker registers actions under this monitor before the stop can traverse them.
|
||||
execution.getActionExecutions().add(registering);
|
||||
}
|
||||
assertEquals(executionId, stopped.get(5, TimeUnit.SECONDS).path("pipelineExecutionId").asText());
|
||||
assertEquals("Abandoned", registering.getStatus());
|
||||
assertEquals("Succeeded", completed.getStatus());
|
||||
assertEquals("Stopping", execution.getStatus());
|
||||
assertTrue(execution.isStopRequested());
|
||||
} finally {
|
||||
service.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private CodePipelineService serviceWith(CodeBuildService codeBuildService,
|
||||
CodeDeployService codeDeployService) {
|
||||
return new CodePipelineService(
|
||||
|
||||
Reference in new issue
Block a user