fix(ecs): delete a service's deployment records with the service (#4757)

DeleteService left the service's ServiceDeployment and ServiceRevision
records behind, so ListServiceDeployments still returned them,
DescribeServices on the INACTIVE service still named a current deployment,
and a service recreated under the same name inherited them. AWS deletes
both with the service; DescribeServiceDeployments and
DescribeServiceRevisions now report the old ARNs as MISSING failures.

This replaces the interim stop-on-delete: a deleted service's deployments
no longer exist, so there is nothing left to mark STOPPED or settle. The
three EcsServiceDeploymentStatusTest cases that pinned a record surviving
the delete are removed, and the steady-state waiter IT that proved
stoppedAt and statusReason reach the wire now reaches STOPPED by
supersession, the route that remains.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-09-30 21:17:55 -04:00
1 parent e377148a52
commit bd0f468d3e
5 files changed
+193 -115

No files matched your search

@@ -2731,15 +2731,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
throw new AwsException("InvalidParameterException",
"The service cannot be stopped. Update the service to 0 tasks or use the force flag.", 400);
}
// Settle against the service as it stands, as UpdateService does: a deployment whose
// tasks are up has finished, whether or not anything read it.
currentServiceDeployment(svc);
svc.setStatus("INACTIVE");
// A deleted service's deployments can never finish, so stop them. This must come before
// setDesiredCount(0): a concurrent read that saw desiredCount 0 on a still-ACTIVE service
// would otherwise mark the deployment SUCCESSFUL. AWS deletes the records instead; that
// is not done here yet.
stopNonTerminalDeployments(svc.getServiceArn(), Instant.now(), "The service was deleted.");
svc.setDesiredCount(0);
cluster.setActiveServicesCount(Math.max(0, cluster.getActiveServicesCount() - 1));
services.put(key, svc);
@@ -2758,6 +2750,13 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
t.getTaskArn(), e.getMessage());
}
});
// AWS deletes the service's deployments and revisions with the service. A service model
// restored from the store may have no ARN, and then owns none.
String serviceArn = svc.getServiceArn();
if (serviceArn != null) {
serviceDeployments.values().removeIf(d -> serviceArn.equals(d.getServiceArn()));
serviceRevisions.values().removeIf(r -> serviceArn.equals(r.getServiceArn()));
}
return svc;
}
@@ -4069,9 +4068,9 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
}
/**
* Marks the service's IN_PROGRESS deployments STOPPED, for a caller that has made them
* unable to finish: a new deployment superseding them, or the service being deleted. Runs
* before the new deployment is added to the map, so it never stops the current one.
* Marks the service's IN_PROGRESS deployments STOPPED, because a new deployment has
* superseded them and they can no longer finish. Runs before the new deployment is added to
* the map, so it never stops the current one.
*/
private void stopNonTerminalDeployments(String serviceArn, Instant now, String reason) {
// A service model restored from the store may have no ARN.