Repository navigation
fix(mpi): an --mpi-command rank ends at its command's exit, not its stragglers' (#1479) - #1480
Merged
Merged
Conversation
… instance state (#1479)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
Live verification on EC2 (2026-11-02), owner-approvedThe CLI was built from this branch at
|
This was referenced Nov 2, 2026
Merged
Merged
Merged
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 #1479
Problem
mpirunran each rank asbash /etc/spawn/mpi-command. Open MPI keeps a rank, and so the job, running until the I/O-forwarding channels it gave that rank close: a pty for stdout and a pipe for stderr, held by mpirun on rank 0 and by orted on the peers. A background job the rank never waited for (sleep 600 &) inherits them. So mpirun,SPAWN_EXITCODEand every member's--on-completewaited out the straggler's whole lifetime, which was 600 s live. The outermpirun … | teepipe was never the holder.Change (owner decision, as for #1459: completion follows the command's own process)
Every member now writes
/etc/spawn/mpi-rank(a here-doc beside/etc/spawn/mpi-command), and the one mpirun invocation runsbash /etc/spawn/mpi-rank. The wrapper:bash /etc/spawn/mpi-commandwith stdout/stderr on a per-rank FIFO (/tmp/spawn-mpi-rank.$$.fifo), which acatcopies to the rank's real stdout. That leaves the forwarded channels held only by the wrapper and thecat.catthe bootstrap: a surviving descendant holding the --command pipe delays SPAWN_EXITCODE and on-complete indefinitely #1459 drain: 100 polls of 0.1 s, 10 s. With nothing holding the output it ends at once./proc, like fix(launcher): complete --command on its own exit, with a bounded output drain (#1459) #1474), kills thecat, and exits with the command's own$?. mpirun then sees the rank end, and a straggler is left holding only a reader-less FIFO.exec bash /etc/spawn/mpi-commandif mkfifo fails (the output and exit code are kept, but not the bound).Other mechanisms I considered: I found no mpirun option that makes it stop waiting on IOF.
setsid/redirecting the user command still needs a reader to forward the output, so it comes back to this wrapper. A straggler that holds only stdin does not delay mpirun (tested), so stdin is untouched.Verified with real mpirun (no AWS)
Local
mpirun --oversubscribe -np 2on one host, with a rank stragglersleep 20 &:kill -TERM $$openmpi, container)AL2 (Open MPI 4.0.1, bash 4.2.46) passes the same tests. On 4.1 a failing rank with a straggler now ends after its 10 s drain, where it used to end at once, because Open MPI aborted the job on the non-zero exit.
Gates (each watched failing against a compiling revert)
TestMPIRankReleasesItsOutputAtTheCommandsExit(exit 0 / 7 / SIGTERM) andTestMPIRankWithoutStragglersAddsNoDelayrun whatever the rendered mpirun line hands a rank, with output on a pipe that stands in for IOF, and count polls through a stubsleep. These run in CI.TestMPIRunEndsAtTheRanksExitWithARealMPIRundoes the same under a realmpirun -np 2. It is skipped when no mpirun is installed.TestEveryMPIRankLaunchRunsTheWrapperfinds every mpirun invocation in the rendered scripts (rank 0, peers, EFA, completion file) and in thecmd/andpkg/Go source. Each must run the wrapper, and every member must write it.TestMPIRankDrainMatchesCommandDrain(pkg/launcher) ties the wrapper's literals tocommandDrainPolls/commandDrainPoll.Size and bootstrap
--mpi-command): 3094 → 3453 gzipped bytes (+359); inline bare bootstrap + MPI: 10033 → 10226.pkg/launcher/bootstrap.gois untouched).Also touched
pkg/instancestate:/etc/spawn/mpi-rankadded toPaths, next to/etc/spawn/mpi-command. ami create: per-instance spored/plugin state (plugins.json, job-array env, peer files) is still baked into images #1241's discovery gate requires it, and the next launch rewrites it. This changes spored's binary but not the bootstrap body.pkg/userdata/shellcheck_test.go: the MPI Check id is nowpkg/userdata.mpiUserDataTemplate. The wrapper's#!/bin/bashhere-doc makes the template a discovered generator, and shellcheckgate now checks the wrapper as a nested script.Follow-up filed: #1481. AL2's Open MPI 4.0.1 ignores
OMPI_ALLOW_RUN_AS_ROOT, so I expect root mpirun to fail on an AL2--ami.