Repository navigation
fix(jobarray): single-gzip the user-data, and always drain a failed cohort - #672
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 4, 2026
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 #671. Both bugs, and your diagnosis was exact on each.
1. Double-gzipped user-data
buildJobArrayMemberConfigbase64-decodedbaseConfig.UserData— whichencodeUserDatahad already gzipped — appended the MPI script to those compressed bytes, and encoded again. Shippinggzip(gzip(bootstrap) + mpiScript).Reproduced as a unit test before fixing; it fails against the old code with exactly the bytes cloud-init logged:
There's now a
decodeUserDatathat is the true inverse ofencodeUserData, with a gzip magic-number check rather than an assumption —encodeUserDataForOSdeliberately 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.goalready 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. ButPhaseis ordered, and an instance exists and bills fromPhaseLaunchAckedonward — so a cohort dying atrunningorenrolledhad launched instances and left every one up. Your twoc8g.48xlargewent terminal atphase=enrolled, which is exactly why they stayed running, and why the placement group reportedInvalidPlacementGroup.InUse.I tried to write this as a
>=phase comparison and it can't be made safe:PhaseLaunchAckedisiota0, so a member that never launched is indistinguishable from one that did byReachedPhasealone.So the drain is now unconditional on cohort failure.
drainJobArrayfilters by thespawn:job-array-idtag, so with nothing launched it's a no-op costing oneDescribeInstances— against a missed drain costing $15/hr. That asymmetry makes it the only defensible default.cleanupAbandonedPGsis 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-docsandsemgrep(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.