Repository navigation
Description
Found by running #671's fix on real hardware. drainJobArray has never terminated a single instance.
#671 made the drain run unconditionally on cohort failure, which was the right gating change. But the drain it was gating cannot match anything, so a failed cohort still leaks its members — the exact cost leak #671 was filed about. My #671 changelog entry overstates the fix and is corrected in the PR for this issue.
Root cause
if in.Tags["spawn:job-array-id"] != jobArrayID {
continue
}listInstancesInRegion (pkg/aws/client.go) lifts every spawn:* tag it recognises into a named field via a switch, and only the switch's default branch writes into the Tags map. spawn:job-array-id has its own case, assigning info.JobArrayID.
So in.Tags["spawn:job-array-id"] is always "", the comparison is always true, every instance is skipped, and the loop terminates nothing. Confirmed against two live instances:
i-0b3f45f11da96cfe8 state=running JobArrayID="repro682-20261004-1931e7" Tags[spawn:job-array-id]="" len(Tags)=25
i-0c84ae578ddab7ec8 state=running JobArrayID="repro682-20261004-1931e7" Tags[spawn:job-array-id]="" len(Tags)=25
25 other tags present; the one the drain needs, absent.
Reproduced twice on real hardware
Two c6i.large as an MPI cohort, failing at phase=enrolled:
⚠️ Cohort failed; draining any launched instances...
drain: no instances matched spawn:job-array-id=repro682-20261004-1931e7
...
⚠️ could not delete abandoned placement group spawn-mpi-repro682-us-east-1a:
InvalidPlacementGroup.InUse
repro682-0: terminal/PhaseBudgetExceeded at phase=enrolled after 2 rung(s)
repro682-1: cohort-cancelled at phase=enrolled — culprit=repro682-0
Final states: index 0 running (leaked, terminated by hand), index 1 shutting-down.
The same shape appeared first on two c5n.9xlarge. CloudTrail showed exactly one TerminateInstances call for that run — and it was for the cancelled member, not the culprit. That terminate comes from cohort's own cancellation path, not from drainJobArray. So the one member that does get cleaned up creates the appearance of a working drain, while the member that actually failed is the one left billing.
This also explains the InvalidPlacementGroup.InUse error in #671's original report: the PG cleanup is deferred and runs after the drain, but the drain left an instance referencing the group.
Why it survived
Three reinforcing reasons, all worth fixing rather than just the line:
- The drain was silent on success. It printed nothing when it worked and nothing when it matched zero instances, so "drained 2" and "drained nothing" were indistinguishable from outside. This is now reported either way, including an explicit warning when a cohort that launched drains nothing.
- Partial cleanup looks like cleanup. Cohort terminating the cancelled member means a failed 2-node run leaves exactly one instance behind, which reads like a race rather than a dead code path.
- The data structure is a trap.
InstanceInfo.Tagslooks like "all the tags" and is actually "only the tags we do not understand". Any lookup of a recognised key silently yields"".
Fix
- Filter on
in.JobArrayIDvia a namedinstanceBelongsToJobArraypredicate, with an empty-id guard (an empty cohort id must match nothing — otherwise a drain with a missing id terminates every instance in the account). - Report what the drain found and did, always.
- A class gate failing the build on any
*.Tags["spawn:…"]read of a recognised key, since (3) is the reusable mistake. It immediately found no other offenders, but it fixes the shape rather than the instance.
Verification is on hardware, not just in tests: the same two-node failure is re-run with the fix and both members must terminate.
Activity