Files
floci/src/main/java/io
Matan Baruch 42bc0d934f fix(ecs): reconcile services in every account, not just the default one (#3297)
* fix(ecs): reconcile services in every account, not just the default one

The reconciler is scheduled on a plain ScheduledExecutorService, so its
thread has no active request scope. Every account-aware storage read inside
it therefore resolves to the default account: AccountAwareStorageBackend
falls back to defaultAccountId when it catches ContextNotActiveException.
reconcileServices() iterates services.entrySet(), so it only ever saw the
default account's services, and the services.put write-back in
reconcileService landed in the default account too.

A service created in any other account stayed at runningCount 0 forever
with nothing logged, while the same service in the default account
converged in about ten seconds. IaC hangs rather than fails on this,
because aws_ecs_service with wait_for_steady_state polls until
runningCount reaches desiredCount.

Enumerate the accounts that own a service through
AccountAwareStorageBackend.scanAllAccountEntries, then run each tick inside
RequestScopes.runAs for that account. That helper exists for this case and
its javadoc says so, and CurEmissionScheduler, AslExecutor and
CloudFormationService already use it. The default account is always
included, so single-account behaviour is unchanged, and the existing
reconcile logic is reused as is.

Each account's work is also guarded. scheduleAtFixedRate silently stops
every future execution if the task throws, so one account's failure must
not kill reconciliation for the rest or for the process.

Fixes #3296.

Verified:
1. EcsReconcilerMultiAccountTest moves a service to a non-default account
   and asserts the reconciler still places its task. It fails without the
   change (expected 1, was 0). EcsReconcileTickResilienceTest covers the
   guard. Full ECS suite green, 191 tests.
2. End to end against the real pulumi-aws v5 provider. An aws_ecs_service
   with wait_for_steady_state in account 000000000001 hung for the full
   600s timeout before the change and reaches steady state in 16s after it.

* fix(ecs): attribute each reconciled task to the account in its ARN

reconcileTasks iterates taskHandles, which is a single in-memory map shared
by every account, so running it inside the per-account loop reconciled every
task once per account. Whichever account ticked first could claim a task
whose containers had exited, leaving the owning account's runningTasksCount
stale and emitting the STOPPED event on the wrong bus.

Reconcile tasks once and scope each task to the account in its own ARN;
only service reconciliation loops over accounts now.

* fix(ecs): log task ARNs the reconciler cannot attribute to an account
2026-09-09 15:18:40 -04:00
..