Repository navigation
fix(launcher): complete --command on its own exit, with a bounded output drain (#1459) - #1474
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…t's last holder exits (#1459)
scttfrdmn
force-pushed
the
fix/1459-command-pipe-drain
branch
from
October 31, 2026 23:59
24e5217 to
9741d86
Compare
This was referenced Nov 1, 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 #1459
What changed
The
--commandblock in the bootstrap body ran the command assu ... 2>&1 | tee -a /var/log/spawn-command.logand read${PIPESTATUS[0]}. A pipeline ends only whenteegets EOF. So any descendant still holding the command's stdout or stderr (an un-waitedaws s3 sync ... &) held back/tmp/SPAWN_EXITCODE, the completion file and--on-complete. Only the TTL bounded that.This implements the owner's decision on #1459: completion is the command's own exit.
teereads a FIFO (/tmp/spawn-command.fifo) in the background, and the command writes to the FIFO.CMD_RCissu's own$?(|| CMD_RC=$?, because the subshell runs underset -e), so non-zero codes and 128+n signal codes are kept as before. I used a FIFO with$!instead of> >(tee ...):$!for a process substitution needs bash 4.4, and AL2 has 4.2.46.kill -0 $teefor at mostcommandDrainPolls(100) polls ofcommandDrainPoll(0.1 s), which is 10 s. If nothing holds the output,teeexits at once and the loop ends./proc/*/fd/*with-efagainst the FIFO. That is a bash builtin, so there is no fork per fd, and the block's ownteeis excluded. It logs one line to the command log and the console:⚠️ spawn: not waiting for processes still holding --command's output after 10s; they run on: <pid> <args> ...Then it writes
SPAWN_EXITCODEand the completion file. The stragglers keep running, and keep logging throughtee.mkfifofails, the output goes to/dev/nullbut completion is still recorded, because a missing record bills to TTL.--commandhelp text (anddocs-gen/launch.md) now says background jobs are not waited for.On-complete and stragglers:
terminatekills them with the instance.stopis an OS shutdown, so systemd kills them. They are not restarted on start: user data is per-instance, and the ami create from a --command instance: SPAWN_* files written after the command get baked in, and the CreateImage reboot re-runs the command #1057 guard applies.hibernatefreezes them with RAM, and they resume when the instance starts.Published bootstrap body changes
Its sha256 changes, so deploy the sweep orchestrator from the next tag. The deploy checklist will show it.
User-data size (bare bootstrap, gzip)
The inline bootstrap had only 30 bytes of slack above the #1422 1 KiB margin.
bootstrapGzipBudgetis raised 8192 → 8448 (+256) in this PR, for review. Release launches carry the stub, whose size is unchanged, so the room lost is a dev build's. I tried de-duplicating the two MOTD heredocs as a reclaim, and it saved only 14 bytes, so I didn't include it. Dropping the comments inside the/etc/profile.dheredocs would reclaim more, but those comments are user-visible file content, so I left them alone.Gates (
pkg/launcher/bootstrap_command_drain_test.go)These run the real
--commandblock in the spot sandbox. A stubsleepon PATH counts the drain polls, so the bounds are counts, not wall-clock. A slowteestub writes each line 0.2 s late, so a block that doesn't drain is caught every time.TestCommandCompletesWhileAStragglerHoldsItsOutput(exit 7, and SIGTERM → 143) checks five things: the straggler is still alive when completion is recorded; there are exactlycommandDrainPollspolls;SPAWN_EXITCODEand the record keep the code; the last line written before exit is in the log ahead of the errexit notice; and the notice names the straggler's PID (where/procexists), not the block's owntee.TestCommandWithoutStragglersAddsNoDelay: fewer thancommandDrainPolls/4polls, and no straggler notice.TestCommandDrainMatchesConstant: the shell literals match the Go constants.Each was watched failing against a compiling revert of
bootstrap.goon Linux (ubuntu:24.04):| teepipeline: "the straggler (pid 40) is gone, so the block waited for it before recording completion" (60 s run)|| true): "SPAWN_EXITCODE = "0", want the command's own 7" / "143", andTestCommandOutcomeIsCapturedfailsThe gates pass on macOS, ubuntu:24.04 (bash 5.2), amazonlinux:2023 (5.2.15) and amazonlinux:2 (4.2.46). Testing on AL2 caught that procps 3.3.10 reads
-o pid=,args=as a single header, so the block uses-o pid= -o args=.Other runners checked
pkg/userdata/mpi.go:381) has the same shape and is NOT changed here:mpirun ... 2>&1 | tee -a ...; spawn_mpi_done "${PIPESTATUS[0]}". Ranks' stdout goes through mpirun's I/O forwarding, not the tee pipe, so only something that inherits mpirun's own stdout would hold it. I have not verified that empirically (no mpirun here).pkg/taskproto/wrapper.go): it runs inside--command, so this fix covers it. It runs the task directly, with no pipe.pkg/agent/queue_runner.go):*os.Filestdout/stderr, socmd.Waitreturns on process exit. Not affected.pkg/taskpool/exec.goviacmd/spored/pool_worker.go):os.Stdout/os.Stderr. Not affected.os.Stdout. Not affected.--commandis refused on Windows (Windows launches silently drop --command and --user-data #1022), and no Windows runner exists.Also
bootstrap_stub_test.go's boot sandbox now linksmkfifo. Without it the command's output went to the/dev/nullfallback: completion was still recorded, but the log was empty.