Repository navigation
fix(bootstrap): make --command wait for storage and MPI setup - #678
Merged
Merged
Conversation
--command is launched from linuxBootstrapBody, concatenated BEFORE the storage script and before anything a caller appends later, so the workload ran without its mounts (df: /efs: No such file or directory) and MPI members started before mpirun had a hostfile or a peer. Adds a readiness barrier: the bootstrap declares the gates, each producer signals its own, and --command waits before starting. The storage gate verifies /proc/mounts rather than trusting an exit code, since the storage script ends in `echo >> /etc/fstab` and always succeeds. Failures surface in /var/log/spawn-command.log and write a failed completion record so --on-complete still fires. The wait is inside the backgrounded subshell (waiting outside blocks cloud-init and leaves spored unarmed — spored#65), and the MPI gate fires before the rank-0 mpirun rather than after it. Fixes #668 Fixes #664
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 #668. Fixes #664.
Done together as one mechanism, as you suggested: one readiness barrier, two producers.
Confirmed as reported
--commandis launched fromlinuxBootstrapBody, whichBuildLinuxBootstrapconcatenates at:178— andStorageScriptis appended at:203, after. So the workload really does run before its mounts exist, which is yourdf: /efs: No such file or directory. #166 fixed this ordering for--user-data(appended at:223, after storage);--commandlives inside the static body and could not be moved the same way.#664 is the same shape one step further out: the MPI script is appended to the whole finished bootstrap by
buildJobArrayMemberConfig, so the workload starts beforempirunhas a hostfile or a peer.I went with your sentinel suggestion rather than reordering. Reordering would have moved the storage script above the body it depends on (
LOCAL_USERNAME,REGION,INSTANCE_ID) and changed whichset -e/set +eregion it runs under — a bigger behavioural change than the bug.How it works
The bootstrap writes
/run/spawn/required-gatesnear the top, each producer writesokorfailed:<reason>to its own sentinel, and--commandwaits for all of them before starting./runis tmpfs, so gates are per-boot by construction.Gates are declared at build time, which is forced rather than chosen: the list is read when the workload begins waiting, so a gate appended at the end of the script text would be announced after the wait had already been skipped. That is why
MPIReadyGateis declared bybuildUserDataeven though the MPI script that signals it is appended later.Three decisions worth your eye
The storage gate verifies the mount instead of trusting an exit code. I started with
STORAGE_RC=$?and then checked what the storage script actually ends with — usuallyecho "... " >> /etc/fstab, which returns 0 whether or not anything mounted. There is no status worth reading, so the gate greps/proc/mountsfor the mount points the launch declared. Only EFS and FSx are required; attached EBS volumes mount withnofailby design and must not strand a workload that never referenced them.The wait is inside the backgrounded subshell. Waiting outside it would block cloud-init, so
sporedwould never start and TTL/idle/cost enforcement would stay unarmed for up to 600s on every launch — the spored#65 failure, and strictly worse than the bug being fixed. There is a test asserting the wait's offset falls between the(and the) &.The MPI gate fires before the rank-0
mpirun, not after. Thatmpirunis the job and can run for hours; gating on its completion would make--commandwait out the entire run, which is indistinguishable from a hang. It fires once the hostfile is built, and reportsfailedfor an empty hostfile — no peers resolved means a cluster of one, which should not read as ready.Failure behaviour, per your last paragraph
An unmet prerequisite now fails loudly in
/var/log/spawn-command.log(not justcloud-init-output.log), says the command never started — "failed" alone reads as a workload that ran and failed, sending you to debug the wrong thing — and writes a failedSPAWN_COMPLETEso--on-completestill fires rather than the instance billing to TTL doing nothing.It fails rather than proceeding, deliberately: a workload started without its mounts does not fail cleanly, it writes to the wrong place or produces silently wrong output.
The risk I was most careful about
A gate declared with no producer would stall every launch for 600s and then fail one that works today. So gates are declared only where a producer is certain, and
readyGatesForLaunchis a tiny pure function with a test pinning both directions. I checkedspawn array retryspecifically — it is plain-array only ("MPI is all-or-nothing"), so a persisted base user-data can never carry an MPI gate into a retry that won't signal it.TestMPIGateDeclaredAndSignalledis the interlock: it asserts both packages agree on the same path, since two tests that each pass alone would not catch a rename on one side.Verification
Every new gate confirmed to fail when its half is reverted — I did this in two passes, removing the declaration side and then the body's wait loop, because the tests split across those:
TestCommandWaitsForStorage,TestMPIGateIsDeclaredfailTestGateWaitIsInsideTheBackgroundedSubshell("no wait loop found"),TestGateFailureIsReportedInCommandLog,TestGateTimeoutMatchesConstantfailAlso avoided a known trap: the mount-point list is interpolated into a shell
forloop, andsecurity.ShellEscapeisstrconv.Quote— Go escaping inside double quotes, where$VARand$(...)still expand. That is #660, still open. This uses real single-quote escaping, with a test for$HOME,$(id), backticks and embedded quotes.Gates clean locally before pushing:
gofmt -lempty,go vet ./...,go test -short ./...(0 failures),make check-docs, changelog gate,semgrep scan --config=auto --error .→ 0 findings.Not verified on hardware, and this is the one where that matters most — it is generated shell, and the tests assert the text of the script, not its behaviour under cloud-init. The ordering and quoting are checkable statically; "the gate actually releases when the EFS mount lands" is not. A single
--efs-id+--command "df -h /efs"launch on the smallest instance would confirm the whole path for cents, and a 2-node MPI run would confirm #664. Happy to run the EFS one if you want it before the release tag.