Skip to content

Task launch dies on a transient "Invalid IAM Instance Profile name" — the fixed 10s propagation sleep loses the IAM→EC2 race; RunInstances isn't retried #572

Closed

Description

@scttfrdmn

Launched three spawn task run specs in parallel from the cookbook. Two started fine; the third died at RunInstances:

launch task: provision: launch: failed to launch instance: InvalidParameterValue:
operation error EC2: RunInstances, https response error StatusCode: 400,
RequestID: e09cc19e-0815-460d-9278-f86378fdfb34,
api error InvalidParameterValue: Value (spawn-instance-0346c413) for parameter
iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name

spawn 0.103.1. No instance was created — RunInstances failed at the API, so this cost nothing (confirmed: describe-instances showed no instance for that task, TTL/cost-cap never engaged). A re-launch ~2 minutes later succeeded with no other change. So the recipe and the spec are fine; this is a launch-time race, and it's the kind that passes CI and most manual runs and then bites a parallel batch.

Root cause: a fixed sleep against IAM→EC2 eventual consistency

The task path gives each task its own scoped profile (cmd/task.go:426, CreateOrGetInstanceProfile), whose name is derived per-policy — so three tasks with different S3 scopes get three distinct, freshly-created profiles (spawn-instance-<hash>). Creation then waits like this:

// Wait for instance profile to propagate (IAM eventual consistency)
time.Sleep(10 * time.Second)

— pkg/aws/iam.go:503, immediately before a GetInstanceProfile confirms it exists (iam.go:507).

Two things make that insufficient:

  1. GetInstanceProfile succeeding proves the wrong thing. It confirms the profile is visible on the IAM control plane. RunInstances consumes the profile through a separate IAM→EC2 propagation path with its own, longer-tailed eventual consistency — AWS documents exactly this and explicitly recommends retrying RunInstances on the transient invalid-profile error. So the confirmation at iam.go:507 can pass while EC2 still 400s.

  2. RunInstances is called once, with no retry on this error. launcher.Provision runs the launch a single time (pkg/launcher/provision.go, the RunInstances tail around :141–:169). A fixed 10s sleep is a bet on the propagation tail being < 10s; under three parallel launches it lost. There is no amount of fixed sleep that closes this — the tail is unbounded — which is why the codebase already treats IAM ops this way for the create calls (retryIAM, iam.go:84) but not for the RunInstances consumption.

That 2-of-3 split is the signature: identical code path, identical 10s wait, and the outcome depended only on timing.

Suggested fix

Retry RunInstances on the specific transient, with backoff — AWS's own recommended pattern, and the mirror of what retryIAM (iam.go:84) already does for the create side:

  • Detect InvalidParameterValue whose message matches Invalid IAM Instance Profile name (there's precedent for message-level classification in pkg/taskproto/completion.go's ClassifyLaunchError).
  • Retry a few times with a short backoff (e.g. 2s, 4s, 8s) before giving up. A handful of seconds beyond the existing 10s covers the normal propagation tail.

Retrying RunInstances is safe here precisely because of the existing #213 ordering: the instance, tags, and any FSx are all created after RunInstances succeeds (provision.go:141, :188, :210), so a rejected call has created nothing to clean up — a retry can't orphan anything.

Two smaller options, weaker on their own: raising the fixed sleep (still a bet, just a slower one), or the doctor already probing IAMInstanceProfileAccess (pkg/doctor/aws_prober.go:146) — but that checks permission, not propagation, so it wouldn't have caught this.

Impact

Bounded — no spend, no orphan, and the failure is loud with a clear AWS error. But it makes parallel task launches flaky, and the natural cookbook pattern is to fire a batch of independent single-tool tasks at once (that's the whole shape: one tool per image, S3 between). Today the mitigation is "re-run the one that died," which works but shouldn't be necessary.

Filed from scientific-codes-cookbook (the three md/viz recipes launched together; the third raced). Related: #570, #571.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions