Skip to content

fix(jobarray): make the failed-cohort drain actually drain, and unbind --subnet-id from AZ fallback - #686

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/683-drain-and-subnet-az
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/683-drain-and-subnet-az

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #683. Both bugs were found by running #659/#668 on real hardware, and both are verified the same way.

The drain never drained

if in.Tags["spawn:job-array-id"] != jobArrayID { continue }

listInstancesInRegion lifts every recognised spawn:* tag into a named field via a switch and writes only unrecognised keys into the Tags map. spawn:job-array-id has its own case. So that lookup is always "", the comparison is always true, every instance is skipped, and drainJobArray terminated nothing, ever.

Confirmed against two live instances rather than inferred:

i-0b3f45f11da96cfe8 JobArrayID="repro682-20261004-1931e7" Tags[spawn:job-array-id]="" len(Tags)=25

25 other tags present; the one the drain needs, absent.

#671's gating fix was right and its claim was wrong. Making the drain unconditional was correct — but I said it "filters by the spawn:job-array-id tag, so with nothing launched it costs one DescribeInstances", which presented a non-functional drain as a working one. I've corrected that entry in this PR rather than only adding a new one.

Why it hid for so long

Three things, and I fixed all three rather than the line:

  1. Silence. The drain printed nothing on success and nothing on matching zero instances, so the two were indistinguishable from outside. It now reports in every case, with an explicit warning when a cohort that launched drains nothing.
  2. Partial cleanup looks like cleanup. Cohort's own cancellation path does terminate the cancelled member, so a failed 2-node run leaves exactly one instance behind — which reads like a race. CloudTrail showed a single TerminateInstances call per failed run, and it was never the drain's.
  3. The data structure is a trap. InstanceInfo.Tags looks like "all tags" and is actually "only tags we don't understand". There's now a gate failing the build on any read of a recognised spawn:* key from that map. It found no other offenders, but the shape is the reusable mistake.

The matching predicate also refuses an empty cohort id — otherwise a drain called without one matches every instance in the account and terminates it.

--subnet-id could not be used with --mpi/--count

A subnet lives in exactly one AZ, but the AZ-fallback chain rewrote Placement.AvailabilityZone:

InvalidParameterValue: Value (us-east-1a) for parameter availabilityZone is invalid.
Subnet 'subnet-05346a3a821a4c093' is in the availability zone us-east-1b

An explicit subnet now takes the same single-rung path a fixed --placement-group already took — the precedent was already there, for the same reason.

This was unreachable until #667, which stopped dropping --subnet-id. So the combination had never worked, and my #667 unit tests could see the subnet arrive on the config but not that it then contradicted the AZ chain. That gap is the honest argument for the hardware run.

Verification on real hardware

Two c6i.large as an MPI cohort, failing at phase=enrolled, before and after:

Before

⚠️  Cohort failed; draining any launched instances...
   drain: no instances matched spawn:job-array-id=repro682-20261004-1931e7
→ index 0: running   (leaked; terminated by hand)
→ index 1: shutting-down  (cohort's cancellation, not the drain)

After

⚠️  Cohort failed; draining any launched instances...
   drained i-0c034e8d1f647b704 (running)
   drain: terminated 1 instance(s)
→ both members: terminated

Leak-checked afterwards across instances, placement groups, security groups, EFS and volumes: all zero.

Also verified in the same session (not changed here)

Filed, not fixed here

Gates

gofmt -l empty, go vet ./..., go test -short ./... (0 failures), make check-docs, changelog gate, semgrep scan --config=auto --error . → 0 findings. Both new gates confirmed to fail against the old code.

…d --subnet-id from AZ fallback

drainJobArray filtered on in.Tags["spawn:job-array-id"], which is always
empty: listInstancesInRegion lifts recognised spawn:* tags into named
fields and writes only UNrecognised keys into Tags. So the comparison was
always true, every instance was skipped, and the drain terminated nothing
— ever. #671 fixed the gating; the drain it gated could not work.

Confirmed against two live instances (JobArrayID set, Tags[...] empty with
25 other tags present) and reproduced twice on real hardware. The one
terminate seen in a failed run comes from cohort's own cancellation path,
so the CULPRIT member was the one left billing while the cancelled one was
cleaned up — which read like a race, not a dead code path.

Also: an explicit --subnet-id is AZ-bound, but the MPI AZ-fallback chain
rewrote Placement.AvailabilityZone, so a pinned subnet got a different
zone and EC2 refused every member. Unreachable until #667 stopped dropping
--subnet-id, so that combination had never worked.

The drain now reports what it found and did in every case; it was silent
on both success and zero matches, which is what hid this.

Verified on real hardware: before, "drain: no instances matched" and a
leaked running instance; after, "drained i-0c03... (running)" and both
members terminated.

Fixes #683
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.07692% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_jobarray.go 23.07% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 98326f4 into main Oct 4, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/683-drain-and-subnet-az branch October 4, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drainJobArray has never terminated anything: it filters on a tag that InstanceInfo.Tags never contains

1 participant