Repository navigation
fix(pool): one worker IAM role per pool; drain removes it (#1147) - #1198
Merged
Merged
Conversation
All pools shared spawn-pool-worker, whose single inline policy is scoped to one run's queue, so a second pool create cut the first pool's workers off. Each pool now gets spawn-pool-worker-<hash of run id>, tagged with its run id. pool drain deletes the role and profile once no worker is pending, running, stopping or stopped, and keeps it (saying how to remove it) while workers remain, since deleting a live worker's role strands it. Fixes #1147
…ng the role nf-spawn drains once at run end, right after which the workers are still terminating; without a bounded wait every nf-spawn run would leave its role behind.
scttfrdmn
force-pushed
the
fix/1147-pool-role
branch
from
October 20, 2026 00:50
f3bda2b to
1c02107
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Each pool now gets its own worker IAM role and instance profile, and
pool drainremoves them once no worker needs them.Fixes #1147
Problem
Every pool shared the role
spawn-pool-worker, and its one inline policy is scoped to a single run's queue.CreateOrGetInstanceProfileoverwrites that policy, so a secondpool createcut the first pool's workers off from their queue.Approach
I used one role per pool rather than accumulating per-run statements on a shared role. Accumulating would need a read-modify-write of a shared document (which races under concurrent creates), would grow toward the 10 KB inline-policy limit, and needs per-run removal. A per-pool role keeps each grant exactly as narrow as before, and removing it is one delete.
spawn-pool-worker-<16 hex of sha256(run id)>. A run id is uncapped and IAM role names stop at 64 characters, so the id is hashed. The role is taggedspawn:pool-run-id.pool draindeletes the role and profile only when no instance tagged with the pool's run id is pending, running, stopping or stopped. Deleting a live worker's role strips its credentials, and spored then cannot terminate it. That is worse than a leftover role. Workers terminate soon after their queue is deleted (fix(pool): workers terminate when drained; idempotent drain; --cost-limit (#1146, #1183) #1192), so drain re-checks every 10 s for up to--wait(new flag, default 2m). This matters because nf-spawn'sSpawnPoolObserverdrains only once, at run end, while the workers are still terminating; without the wait every nf-spawn run would leave its role behind. If workers remain after the wait, or the check itself fails, drain keeps the role and prints how to remove it (re-runspawn pool drain).spawn orphansis the backstop.Client.DeleteInstanceProfileAndRoleandClient.LiveInstancesWithTag. The second returns the describe error, whereListInstancesswallows per-region errors, because an empty result here leads to a deletion.Gates (each watched failing against a revert that compiles)
TestConcurrentPoolCreatesKeepTheirOwnGrants: two goroutines run the realCreateOrGetInstanceProfileagainst a stateful, recording IAM+STS Query fake (httptest), then check each pool's profile grants only its own queueRoleName: "spawn-pool-worker"TestDrainRemovesThePoolRoleOnlyOnceNoWorkerNeedsIt/workers_still_livelen(live) > 0 && false.../check_failederr != nil && falseTestLiveInstancesWithTagReturnsTheDescribeErrorTestDrainWaitsForWorkersBeforeRemovingTheRole: live counts 3,1,0 delete on the 3rd check after 2 sleeps; never-zero exhausts exactly--wait/10s polls; checks counted through a sleep seamwaited >= 0(no wait) /waited += 0(unbounded; the capped fake sleep turns the hang into a failure)Merge note
Rebased onto main after #1192 and #1200 merged. Drain now runs: idempotent queue delete (#1192), then the role cleanup with
--wait. The cleanup also runs on an "already drained" re-run, because a re-run is how a role kept for live workers gets removed. #1200'sTestIdleTerminateClaimsAreTruepasses with the new--waithelp.Checks
make check: all steps passed exceptcheck-build-tags, which fails on the/private/tmpworktree path (known on main).make check-docs: clean.semgrep --config=auto --error: clean.-raceon the new tests: pass.Not verified
Not run on AWS. Neither the deletion against real IAM nor the caller permissions drain now needs (
iam:DeleteRole,iam:DeleteInstanceProfile,iam:DeleteRolePolicy,iam:DetachRolePolicy,iam:RemoveRoleFromInstanceProfile,iam:List*) has been exercised live. Accounts that already have the old sharedspawn-pool-workerrole keep it; it shows up inspawn orphans.