Repository navigation
fix(aws): retry RunInstances on IAM instance-profile propagation race (#572) - #576
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…race (#572) CreateOrGetInstanceProfile's fixed 10s sleep + GetInstanceProfile check only proves IAM control-plane visibility for a freshly-created scoped instance profile. RunInstances consumes the profile through EC2's own, separately eventually-consistent propagation path, which AWS documents and recommends retrying against. Under parallel `spawn task run` launches, one profile lost that second race and RunInstances 400'd with InvalidParameterValue: Invalid IAM Instance Profile name, even though the other concurrent launches (with different scoped profiles) succeeded on identical code. RunInstances now retries specifically on this transient, detected by AWS error code (InvalidParameterValue) + message substring ("Invalid IAM Instance Profile name") — not on any InvalidParameterValue, which would waste time retrying genuinely bad config (bad instance type, bad AMI, etc.) before failing the same way. Backoff is bounded (2s/4s/8s); any other error still fails immediately with no retry. Safe to retry: Provision creates the instance record, tags, and any ephemeral FSx strictly after RunInstances succeeds (#213), so a rejected RunInstances call has created nothing — a retry attempt accumulates no partial state to clean up.
scttfrdmn
force-pushed
the
fix/572-runinstances-iam-race
branch
from
September 5, 2026 01:35
c03c525 to
af174b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #572:
spawn task run(and any headless launch through a freshly-created scoped IAM instance profile) could failRunInstanceswith a transientInvalidParameterValue: ... Invalid IAM Instance Profile name, even thoughCreateOrGetInstanceProfile(pkg/aws/iam.go) already waited 10s and confirmed the profile viaGetInstanceProfile.Root cause: that confirmation only proves IAM control-plane visibility.
RunInstancesconsumes the instance profile through EC2's own, separate IAM→EC2 propagation path, which AWS documents as independently eventually-consistent and explicitly recommends retryingRunInstancesagainst. Under three parallelspawn task runlaunches (each getting its own per-task scoped profile, since profile names are derived from a hash of the policy content), one profile lost that second race even though the other two — running identical code — succeeded.Fix:
pkg/aws/client.go'sLaunchnow callsRunInstancesthrough a newrunInstancesWithRetryhelper that retries only this specific transient:isTransientIAMInstanceProfilePropagation): AWS error codeInvalidParameterValueand the error message contains"Invalid IAM Instance Profile name"— mirroring the message-level classification style already used bypkg/taskproto/completion.go'sClassifyLaunchErrorand the code-based checks inpkg/aws/iam.go(isAlreadyExists,isThrottle).2s, 4s, 8s(3 retries max), mirroring the shape of the existing create-sideretryIAM(pkg/aws/iam.go:84) but sized for the consumption-side tail on top of the existing 10s create-side wait.InvalidParameterValue(bad instance type, bad AMI, etc.) or any other AWS error — returns immediately with no retry. This is deliberately narrow so the fix can't become a blanket retry-on-any-launch-error mechanism.Ordering / orphan-safety check (explicitly requested in the issue): confirmed by reading
pkg/launcher/provision.go— the instance record, tags, and any ephemeral FSx are all created strictly afterRunInstancessucceeds (see the#213comments at provision.go:141 and provision.go:159-179). A rejectedRunInstancescall has created nothing, so retrying it accumulates no partial state and cannot orphan anything. This assumption held; no change of approach was needed.Not done: raising the fixed 10s sleep. As the issue notes, that's still a bet against an unbounded tail, just a slower one — this fix retries on the actual failure instead.
Changes
pkg/aws/client.go: addedisTransientIAMInstanceProfilePropagation,runInstancesAPI(narrow interface, mirrorsdescribeInstancesAPI/describeVolumesAPIincleanup.go),iamInstanceProfilePropagationBackoff,runInstancesSleep(test seam), andrunInstancesWithRetry; wired intoLaunch'sRunInstancescall site.pkg/aws/runinstances_retry_test.go(new): classifier tests (exact 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 repro classified transient; differentInvalidParameterValuemessages and other error codes classified not-transient) + retry-loop tests (succeeds after N transient failures; gives up with a clear error when the transient never clears, bounded not infinite; no retry at all on a different error class).CHANGELOG.md:### Fixedentry under## [Unreleased]referencing 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.Test plan
go test ./pkg/aws/... -run "TestIsTransientIAMInstanceProfilePropagation|TestRunInstancesWithRetry" -vclient.gochange (keeping the new test file) makes the package failgo vet(undefined symbols) — the tests are load-bearing on the fix, not tautological.go test -short ./pkg/aws/... ./pkg/launcher/...— all green, no regressions.make check— clean (fmt, vet, short tests all pass).go run . gen-docs --out docs-gen— no diff (this change touches no flag/help text).for d in lambda/*/; do (cd "$d" && go build ./...); done) — all build clean, nogo mod tidyneeded.lambda/autoscale-orchestrator/autoscale-orchestratorgot locally rebuilt by the lambda build loop as expected; reverted before committing, confirmed not in the diff.