Skip to content

bootstrap: a surviving descendant holding the --command pipe delays SPAWN_EXITCODE and on-complete indefinitely #1459

Closed

Description

@scttfrdmn

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_EXITCODE

A 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 0

harness.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:

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

  1. added
    bug
    on Oct 31, 2026
  2. scttfrdmn commented on Oct 31, 2026

    @scttfrdmn
    ContributorAuthor

    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.

  3. added this to the v0.154.0 milestone on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions