mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
AWS CloudFormation reports an AWS::ECS::Service CREATE_COMPLETE or UPDATE_COMPLETE only once the service is stable: it polls DescribeServices until the desired number of tasks of the current task definition are running. Floci reported the resource complete as soon as CreateService or UpdateService returned. The tasks were started later by the ECS reconciler, every five seconds, and the service's runningCount only caught up a tick after that, so a client reading the service right after the stack operation saw runningCount 0. EcsService.awaitServiceStable now waits, like Ec2Service.awaitContainerLaunch, for runningCount to equal desiredCount, for the current deployment to run that many tasks, and for no task of an earlier deployment to be running. Instead of idling until the next tick it submits up to three reconcile passes to the single reconciler thread, so they never overlap a scheduled tick. After five minutes it fails with "Service <arn> did not stabilize.". The wait ends at once when the service's tasks cannot start. The reconciler now keeps, in memory, why its last attempt to launch a task for a service failed, for example an unknown subnet, and the deployment it was launching for. Only a failure of the deployment being awaited ends the wait, so a pass that began before an update cannot fail the update. The record is cleared on a successful launch, on DeleteService and on a state reset. A task that stops with TaskFailedToStart during the wait ends it too. A task the reconciler launches is stamped with the deployment read before its task definition, not after the launch, so a launch that an update overtakes counts as the earlier deployment's and is replaced. The ECS provisioner calls the wait after an in-place update and after a create. A created service stays marked as owned by the stack while it waits, so the create rollback deletes it. A replacement created by a stack update is deleted when it does not stabilize. A service updated in place that does not stabilize is put back on the task definition, desired count and network configuration it had, and the provisioner waits for that to stabilize too, as CloudFormation's rollback does. A restore that fails or does not stabilize is reported as a rollback failure, so a rolled-back stack does not claim the prior configuration is running when it is not. The ECS service test in CloudFormationIntegrationTest used subnets and a security group that do not exist, so its tasks could never start. It now uses the default VPC's.