Skip to content

fix(mpi): an --mpi-command rank ends at its command's exit, not its stragglers' (#1479) - #1480

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/1479-mpi-rank-stragglers
Nov 2, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/1479-mpi-rank-stragglers

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1479

Problem

mpirun ran each rank as bash /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_EXITCODE and every member's --on-complete waited out the straggler's whole lifetime, which was 600 s live. The outer mpirun … | tee pipe 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 runs bash /etc/spawn/mpi-rank. The wrapper:

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 2 on one host, with a rank straggler sleep 20 &:

Open MPI shape exit 0 exit 7 kill -TERM $$ no straggler
4.1.2 (AL2023 openmpi, container) old 20 s, rc 0 1 s, rc 7 (the abort kills the group) rc 143 0 s
4.1.2 wrapper 10 s, rc 0 12 s, rc 7 rc 143 0 s
5.0.11 (Homebrew) old 20 s, rc 0 20 s, rc 7 rc 143 0 s
5.0.11 wrapper 11 s, rc 0 11 s, rc 7 rc 143 0 s

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) and TestMPIRankWithoutStragglersAddsNoDelay run whatever the rendered mpirun line hands a rank, with output on a pipe that stands in for IOF, and count polls through a stub sleep. These run in CI.
  • TestMPIRunEndsAtTheRanksExitWithARealMPIRun does the same under a real mpirun -np 2. It is skipped when no mpirun is installed.
  • TestEveryMPIRankLaunchRunsTheWrapper finds every mpirun invocation in the rendered scripts (rank 0, peers, EFA, completion file) and in the cmd/ and pkg/ Go source. Each must run the wrapper, and every member must write it.
  • TestMPIRankDrainMatchesCommandDrain (pkg/launcher) ties the wrapper's literals to commandDrainPolls/commandDrainPoll.

Size and bootstrap

  • MPI user-data fragment (trivial --mpi-command): 3094 → 3453 gzipped bytes (+359); inline bare bootstrap + MPI: 10033 → 10226.
  • The published bootstrap body does not change (pkg/launcher/bootstrap.go is untouched).

Also touched

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.

@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live verification on EC2 (2026-11-02), owner-approved

The CLI was built from this branch at 78f49eeb (spawn version 0.154.1-0.20261102000201-78f49eeb6611). The run was in account 942542972736, us-east-1, with the same launch config that found #1479: 2× c7g.medium, --mpi --mpi-processes-per-node 1 --auto-placement-group=false, and a rank command of sleep 600 & echo rank-$RANK-exit; …; exit 0.

  • The wrapper is in place: /etc/spawn/mpi-rank exists on both nodes, and mpirun runs bash /etc/spawn/mpi-rank.
  • Timing: both ranks exited at 1793578091.03. SPAWN_EXITCODE (content 0) was written at 1793578101.22, +10.19 s. The --mpi-command: a background process started by a rank holds back SPAWN_EXITCODE and --on-complete until it exits (mpirun waits on its I/O forwarding; #1459 for MPI) #1479 baseline was +600.0 s. SPAWN_COMPLETE was written on both nodes 0.25 s later.
  • Rank 1 through orted/ssh finished in the same window.
  • Log: both rank-N-exit lines were kept, along with these notices:
    spawn: rank 1: not waiting for processes still holding --mpi-command's output after 10s; they run on: 29658 sleep 600
    spawn: rank 0: … 29624 sleep 600
  • Exit code: in the same cluster, by hand: rank 1 exit 7 gave mpirun's abort message and mpirun_rc=7. (This didn't go through spawn_mpi_done.)
  • Shutdown: shutting-down came about 81 s after completion (spored's tick plus the 30 s completion delay).
  • Cost and cleanup: about $0.005. Both instances terminated by on-complete, and the MPI SG spawn-mpi-live1480 was deleted. The leak check against the baseline was clean across 10 resource types, and independently confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant