Repository navigation
fix(pool): survive the instance-profile race, name each missing worker, retry a run id (#1448) - #1453
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…r, retry a run id (#1448) WIP: tests for cmd to follow.
…tes; explain QueueDeletedRecently
scttfrdmn
force-pushed
the
fix/1448-pool-iam-race
branch
from
October 31, 2026 00:25
494dbb4 to
0977e12
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.
Fixes #1448
All four problems in the issue and its comment are fixed. Root cause first.
1. Workers lost to the instance-profile race: cause (d), the cohort's launch budget
The pool path does call
runInstancesWithRetry(cmd/pool.go →taskcohort.Actuator.Launch→aws.Client.Launch→runInstancesWithRetry), and the classifier matches the pool's error, so it was neither (a) nor (b). The cause is (d):provisionPoolWorkersbuilt the cohort withcohort.DefaultBudget(), which givesLaunchAcked15 s. The reconciler wraps each worker'sLaunchincontext.WithTimeout(ctx, budget.LaunchAcked).Client.Launchmakes its own calls first (identity, account name, the price through truffle, the launch-config object in S3, DescribeImages). Then comes the 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 retry, which by itself needs 2+4+8 = 14 s.runInstancesSleepwastime.Sleep, which ignores ctx. A worker still rejected at its third attempt slept 8 s past the deadline. Its nextRunInstancesthen failed on the client side withcontext deadline exceeded, so nothing was sent.This matches the CloudTrail: all four rejected at 19:47:41, worker-3 retried at :43, three succeeded at :48 (the third attempt, about 7 s in), and no further call for worker-1. Pool 1 has the same shape.
Fix. The pool's budget is now
poolCohortBudget():LaunchAcked = aws.InstanceProfilePropagationRetryWindow() + 1mfor Launch's own calls. The backoff is extended to 2/4/8/16/30 s (60 s in total) for IAM's longer tail. The sleep now honours ctx.2. Empty failure reason: dropped in two places
smithy.APIError.runInstancesWithRetrynow returnsRunInstances retry stopped (<ctx err>) after N attempt(s) rejected with: <AWS err>, which wraps both.newLaunchErrorextractsInvalidParameterValueagain.taskcohort.Classifiernow also takes the code from a bare AWS error, and uses AWS's own message, noting a deadline.Fault.Message), butcohort.Record.Summary()renders onlyClass/Code.poolMemberReasonrenders the code and message, for the culprit and for each cohort-cancelled survivor:terminal/InvalidParameterValue: Value (…) for parameter iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name at phase=launch-acked ….3. "ready" hid a 1-of-4 pool
The output is now
✅ Pool "X" ready: 1 of 4 workers (min viable 1), queue created., followed by⚠️ 3 worker(s) did not come up; the pool runs with 1:and one line per missing worker with its reason. The failure error also says how many came up.pool createhas no JSON output: it writes only to stderr and ignores the global-o, so there was no JSON to change.4.
IdempotentParameterMismatchon a retry with the same run idWhat differs. The token was
cohort.Token("pool", "<run>-worker-<i>", "g1"), fixed per run id and worker. The request is not fixed:buildTagsstampsspawn:launch-timeandspawn:ttl-deadline(RFC 3339, to the second, fromtagClock) on both the instance and volume TagSpecifications. Pool workers always have a TTL (--ttl 4h). User data, profile name, AMI and instance type are deterministic, andTestAnchorLaunchTagsMovesEveryInstantalready shows these two tags are the ones that move.Choice: scope the token, not freeze the parameter. The timestamps are right to differ, because a retried pool's TTL must run from its own launch. So the token's generation is now the run queue's incarnation, its SQS
CreatedTimestamp(taskpool.Queue.Incarnation).Why this can't create duplicate workers:
pool createalso refuses up front, in plain words, when the run has live workers (poolLiveWorkers, matched on thespawn:pool-run-idtag), and points atspawn pool drain.sqs:GetQueueAttributes,pool createwarns and scopes tokens to the attempt (a random nonce). Retry still works, and only the token backstop for a live pool is lost.QueueDeletedRecently.taskpool.CreateQueuenow says to retry in a minute.Gates (each watched failing against a compiling revert)
cmd TestPoolLaunchBudgetHoldsTheProfileRetryWindow(real Reconciler + taskcohort seam, min-viable 1 and 4)poolCohortBudget=DefaultBudget()0 came uppkg/aws TestRunInstancesWithRetry_PoolWorkersOutlastTheProfileRace(4 concurrent workers, all rejected until the profile propagates; counted through the sleep seam, simulated clock, no wall-clock)45ssubtest fails (the 7 s CloudTrail case passes under both: the schedule was not the cause, the budget was)pkg/aws TestRunInstancesWithRetry_StoppedRetryKeepsTheAWSErrorretryStoppedreturns ctx err onlypkg/taskcohort TestClassifierFaultCarriesTheAWSReasonerr.Error())cmd TestPoolFailureNamesTheAWSError,…WhenTheDeadlineEndsTheRetryrec.Summary()cmd TestPoolReadySaysHowManyWorkersExistcmd TestPoolCreateRetriesUnderTheSameRunID,TestPoolCreateCannotDuplicateALivePool(fake EC2 that remembers tokens incl. rejected ones and moves launch-time per call)"g1"terminal/IdempotentParameterMismatch(the comment's symptom reproduced); tokens shared across incarnationsChecks
make check(from /private/tmp) passes,make lintreports 0 issues,semgrep scan --config=auto --error .is clean, andmake check-docspasses.make api-snapshotaddsaws.InstanceProfilePropagationRetryWindowand(*taskpool.Queue).Incarnation.make cli-iam-actionsaddssqs:GetQueueAttributestospawn pool create.pool statusalready needs that action, andpool createdegrades with a warning without it.Deploy checklist (
make deploy-checklist FROM=v0.151.0 TO=HEAD)lambda/pipeline-orchestratorandlambda/sweep-orchestratorshow as code-only because they compilepkg/aws/client.go. Both callec2Client.RunInstancesdirectly and never reachrunInstancesWithRetry, so the change does not alter their behaviour. The other manual entry,setup-lambda-deploy-ci-role.sh, comes from #1445 on main, not from this PR.