Skip to content

fix(jobarray): single-gzip the user-data, and always drain a failed cohort - #672

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/671-double-gzip-and-cohort-leak
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/671-double-gzip-and-cohort-leak

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #671. Both bugs, and your diagnosis was exact on each.

1. Double-gzipped user-data

buildJobArrayMemberConfig base64-decoded baseConfig.UserData — which encodeUserData had already gzipped — appended the MPI script to those compressed bytes, and encoded again. Shipping gzip(gzip(bootstrap) + mpiScript).

Reproduced as a unit test before fixing; it fails against the old code with exactly the bytes cloud-init logged:

got first bytes: "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xff\x00)\x00\xd6\xff#"

There's now a decodeUserData that is the true inverse of encodeUserData, with a gzip magic-number check rather than an assumption — encodeUserDataForOS deliberately doesn't gzip for Windows (EC2Launch can't decompress), and one existing test feeds plain base64, so both round-trip.

One thing worth flagging: cmd/launch_jobarray_test.go already had a correct private decoder for its assertions, while the production path did the wrong thing. The knowledge was in the repo and simply not shared. That helper now delegates to the production function, so the tests exercise the same code the builder uses.

2. The failed cohort left its instances running — the expensive half

The drain required ReachedPhase == PhaseCohortAssembly. But Phase is ordered, and an instance exists and bills from PhaseLaunchAcked onward — so a cohort dying at running or enrolled had launched instances and left every one up. Your two c8g.48xlarge went terminal at phase=enrolled, which is exactly why they stayed running, and why the placement group reported InvalidPlacementGroup.InUse.

I tried to write this as a >= phase comparison and it can't be made safe: PhaseLaunchAcked is iota 0, so a member that never launched is indistinguishable from one that did by ReachedPhase alone.

So the drain is now unconditional on cohort failure. drainJobArray filters by the spawn:job-array-id tag, so with nothing launched it's a no-op costing one DescribeInstances — against a missed drain costing $15/hr. That asymmetry makes it the only defensible default.

cleanupAbandonedPGs is deferred, so it still runs after the drain. Termination is asynchronous, so a PG delete may still race a shutting-down instance; that stays best-effort, since an empty placement group is free.

Verification

Both gates confirmed to fail when reverted — the user-data test reports the gzip magic bytes, and the drain test rejects both the phase equality and the conditional. Full suite, go vet, gofmt, make check-docs and semgrep (0 findings) all clean.

Not verified on hardware. A real 2-node launch is the end-to-end proof and costs ~$15/hr on c8g.48xlarge-class instances, so I haven't run one. The decode-once assertion reproduces the exact symptom you saw, which is the part that was silent — but if you have a cheap instance type that still exercises the MPI path, a confirmation run would be worth having before the next release.

…ohort

Two bugs from #671, both in the job-array/MPI path.

DOUBLE-GZIPPED USER-DATA. buildJobArrayMemberConfig base64-decoded
baseConfig.UserData — which encodeUserData had already GZIPPED — appended the MPI
script to those compressed bytes, and encoded again, shipping
gzip(gzip(bootstrap) + mpiScript). cloud-init unwraps one layer, finds binary,
logs "Unhandled non-multipart (text/x-not-multipart) userdata" and skips
everything. So NO job-array or MPI member has ever run its bootstrap: no spored,
no peers file, no hostfile. With spored absent, nothing on-instance enforced
spawn:ttl either.

Added decodeUserData as the true inverse of encodeUserData, with a gzip
magic-number check rather than an assumption — encodeUserDataForOS deliberately
does NOT gzip for Windows (EC2Launch cannot decompress), and one existing test
feeds plain base64, so both round-trip.

Worth noting: cmd/launch_jobarray_test.go already had a CORRECT private decoder
for its assertions while the production path did the wrong thing. The knowledge
was in the repo and simply not shared. That helper now delegates to the
production function, so the tests exercise the same code the builder uses.

FAILED COHORT LEFT INSTANCES RUNNING. The drain required ReachedPhase ==
PhaseCohortAssembly. Phase is ORDERED, and an instance exists and bills from
PhaseLaunchAcked onward, so a cohort dying at `running` or `enrolled` had
launched instances and left every one up. The reporter's two c8g.48xlarge
($7.66/hr each) went terminal at phase=enrolled and stayed running until
terminated by hand — which is also why the placement group could not be deleted.

A phase predicate cannot be made safe here: PhaseLaunchAcked is iota 0, so a
member that never launched is indistinguishable from one that did by ReachedPhase
alone. The drain is now unconditional on cohort failure. drainJobArray filters by
the spawn:job-array-id tag, so with nothing launched it is a no-op costing one
DescribeInstances — against a missed drain costing $15/hr. cleanupAbandonedPGs is
deferred so it still runs after; a PG delete may race a shutting-down instance,
which stays best-effort because an empty placement group is free.

Both gates confirmed to fail when reverted: the user-data test reports the gzip
magic bytes (\x1f\x8b\b) cloud-init actually logged, and the drain test rejects
both the phase equality and the conditional.

Not verified on hardware: a real 2-node launch is the end-to-end proof and costs
~$15/hr on c8g.48xlarge-class instances. The decode-once assertion reproduces the
exact reported symptom, which is the part that was silent.

Fixes #671
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.94118% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_config.go 57.14% 3 Missing and 3 partials ⚠️
cmd/launch_jobarray.go 33.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

--count/--mpi job arrays ship DOUBLE-gzipped user-data: cloud-init runs nothing, members never enroll, and the failed cohort leaves instances running

1 participant