Repository navigation
Description
Summary
When multiple spawn launch invocations run concurrently, they race in the "Setting up IAM role" step on the shared spored-instance-role / instance profile, and some launches fail with exit 1 at that step.
Evidence
Tier 2 e2e (3 parallel launches) repeatedly failed at ~5s, all at ⏳ Setting up IAM role:
spawn launch e2e-iam-policy-... --iam-policy s3:ReadOnly failed: exit status 1 # at "Setting up IAM role"
spawn launch e2e-prestop-... failed: exit status 1 # same
spawn launch e2e-ambiguous-... failed: exit status 1 # same
A single launch (and 2-3 launches that happen to win the race) succeed. Run serially, all pass.
Likely cause
All instances share one spored-instance-role + instance profile. Concurrent launches each try to ensure-create/attach it (pkg/aws/iam.go — CreateRole/PutRolePolicy/AttachRolePolicy/CreateInstanceProfile/AddRoleToInstanceProfile). Concurrent creates collide: EntityAlreadyExists, LimitExceeded/Throttling, or NoSuchEntity (TOCTOU between exists-check and use), and the code doesn't treat the already-exists/throttle cases as benign + retry.
--iam-policy adds per-launch PutRolePolicy calls, widening the race window — hence the IAM-policy test was the most reliable failure.
Fix direction
- Make IAM role/profile setup idempotent and concurrency-safe: treat
EntityAlreadyExistsas success; retry onThrottling/LimitExceededwith backoff; handle the create-then-immediately-use propagation gap. - Consider an advisory lock or "ensure once" path so N concurrent launches don't all attempt the create.
--iam-policyper-launch inline policies on a shared role are also semantically odd (one launch's policy affects the shared role) — worth confirming whether per-launch policies should go on a per-instance role instead.
Relation to #58
This is a concrete instance of the concurrent-launch scaling concern (#58). The e2e harness now caps launch concurrency (lowered launchSem) to avoid triggering it in tests, but the real fix is making IAM setup concurrency-safe so real users running parallel launches / sweeps don't hit it.
Context
Found in #61 Tier 2 work. The e2e tests for IAM-policy / pre-stop / name-resolution all failed at launch due to this race, not their actual assertions.
Activity
scttfrdmn commentedon Jun 6, 2026
Fixed in #69. IAM role/profile setup is now idempotent:
retryIAMtreats already-exists as success and retries throttling, applied to CreateRole/CreateInstanceProfile/AddRoleToInstanceProfile. Verified with TestCreateOrGetInstanceProfile_Concurrent (8 concurrent goroutines ensuring the same role all succeed). e2e launchSem raised 1→4 now that concurrent launches converge instead of racing.fix: --command as instance user, idempotent IAM, Tier 2 fixes (#61, #64…
fix(iam): retry ConcurrentModification, and make terminate idempotent (…