Repository navigation
Description
Follow-up from #1456 (item 6 of its fix brief): investigated, mechanism reproduced locally, not fixed there.
What happens
The bootstrap runs --command as (pkg/launcher/bootstrap.go:1419-1423 on main at f51a577):
su - "$LOCAL_USERNAME" -c '/tmp/spawn-command.sh' 2>&1 | tee -a /var/log/spawn-command.log
CMD_RC=${PIPESTATUS[0]}
echo "$CMD_RC" > /tmp/SPAWN_EXITCODEA pipeline finishes only when every member has exited, and tee exits only at EOF on its stdin. Any descendant of the command that is still alive and still holds the inherited stdout/stderr (a cmd & the script did not wait for, a daemon that did not redirect its fds, a grandchild that survived a SIGTERM to its parent) keeps the pipe's write end open. So SPAWN_EXITCODE and the completion file are not written until that descendant exits or closes its fds, and spored's completion path (1-minute poll, --completion-delay, terminate) does not start until then. Nothing bounds the wait except the TTL.
Evidence (local, no AWS; bash -c standing in for su - -c, which likewise forks the command and leaves the pipe fds with its descendants)
cmd.sh:
#!/bin/bash
trap 'echo "workload EXIT trap $(date +%s)"' EXIT
( sleep 6 ) & # a descendant that outlives the command, inheriting stdout
echo "workload done $(date +%s)"
exit 0harness.sh (the bootstrap's three lines):
bash -c "$D/cmd.sh" 2>&1 | tee -a $D/log
CMD_RC=${PIPESTATUS[0]}
echo "SPAWN_EXITCODE=$CMD_RC written at +$(( $(date +%s) - start ))s"Output:
workload done 1793464238
workload EXIT trap 1793464238
SPAWN_EXITCODE=0 written at +6s
The same run with the descendant's fds redirected (( sleep 6 ) >/dev/null 2>&1 &): SPAWN_EXITCODE=0 written at +0s.
So the EXIT-trap line is not a reliable "done" marker: the instance can sit for as long as any descendant keeps the pipe open. This is a plausible cause of the >= 2m50s case in #1456 (measured from the workload's exit line, after a SIGTERM to a child), but that run's state was not captured, so it is not proven to be that case. The other measured case in #1456 (18 s from EXIT trap to SPAWN_EXITCODE) is consistent with the trap itself still running (it was syncing logs to S3).
Why not fixed in #1456
The obvious change, su ... > >(tee -a /var/log/spawn-command.log) 2>&1; CMD_RC=$?, makes the exit code independent of tee, but:
- tee may still be draining when the bootstrap appends the spawn launch --command runs under bash -e, invisibly: 'set -uo pipefail' does not clear it, and the script dies before it can report why #707/Job arrays: per-member output is clunky (errexit preamble in every command log, EC2 hostnames, one raw ssh line per member) #897 errexit notice, which must come after the last line of a failed command's output, and when the completion file is written, so the end of the log can be cut off or reordered; a
waitfor the process substitution brings the original delay back, so it needs a bounded wait; - it is a behaviour decision: today a forgotten
aws s3 sync ... &that inherits stdout accidentally gets to finish before on-complete terminates the instance. Not waiting for it would terminate it mid-upload. The owner should decide whether spored waits for descendants (bounded? logged?) or ends at the command's own exit.
Suggested direction (for discussion)
Take the exit code from the command itself (process substitution or wait $pid), wait for the tee a bounded few seconds so the log tail is complete, and log loudly when descendants are still holding the output (e.g. fuser//proc/*/fd scan, or just "log writer still open after Ns"). Keep it inside the user-data budget (TestBareBootstrapFitsItsBudget).
Activity
scttfrdmn commentedon Oct 31, 2026
Owner decision (2026-10-31): complete on the main process's exit. Record completion when
--command's own process exits. Then stop waiting on the pipe after a short, bounded drain (on the order of 10 s), so the log tail is kept. Leftover background processes are killed at terminate, so you pay for your command, not for stragglers. Milestoned v0.154.0.fix(launcher): complete --command on its own exit, not when its outpu…
fix(launcher): complete --command on its own exit, not when its outpu…