You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document on-complete termination latency (~1–1.5 min after --command exit) and where spored logs #1456
With spawn launch --command … --on-complete terminate (spawn 0.151.0, commit 0fad91e), the instance kept running for at least 2 min 50 s after --command exited. The default --completion-delay is 30 s. In an earlier identical launch it terminated about 1.5 min after exit, so the behaviour is inconsistent. It isn't a cost problem (TTL and cost limit stayed in force), but the caller can't rely on termination at exit.
Launch
AL2023 arm64, us-east-1, Spot, from a shell script:
The workload exits through a trap … EXIT that syncs logs to S3. Exit times below are from the workload's own log line, written in that trap just before exit.
Observations
Launch
Instance
Workload exit (UTC)
Exit code
State afterwards
run 3
i-026a7fd672ded2239 (r8gd.4xlarge)
03:31:04
137 (child OOM-killed; script set -e)
shutting-down at 03:32:31 (on its own, ~1.5 min)
run 4
i-0c580d947404f5424 (r8gd.8xlarge)
05:01:27
143 (I sent SIGTERM to the workload's child; the script exited)
still running at 05:04:17 (2 min 50 s); terminated with spawn terminate --yes
run 5
i-05105778e8c9daf07 (r8gd.4xlarge)
05:15:02
0
still running at 05:16:53 (1 min 51 s); terminated manually. Inconclusive, given run 3's 1.5 min
All three were launched the same way; only the exit path differed. Run 4 is the clear case: its exit came after an external SIGTERM to a grandchild of the command, with the script then exiting 143 through its EXIT trap.
Expected
The instance moves to shutting-down within --completion-delay (30 s) plus spored's poll interval after /tmp/SPAWN_EXITCODE is written, whatever the exit code or how the command ended.
Possibly related
#224 (lifecycle tied to the spawn:command process). If killing the workload's child changes how spored sees command completion, run 4 may be that path.
I didn't capture spored's log before terminating; the instances are gone. Next time I'll grab /var/log/spored* and /tmp/SPAWN_EXITCODE before terminating by hand.
Correction with a measured case (2026-10-31, spawn 0.151.0, c8gd.16xlarge Spot, AL2023): this time I waited and captured state before doing anything.
Workload's final log line (its EXIT trap): 06:18:09Z, exit 0.
/tmp/SPAWN_EXITCODE = 0, written 06:18:27.368Z; /tmp/SPAWN_COMPLETE written 06:18:27.378Z. That's 18 s after the trap line, which was still syncing logs to S3.
Still running at 06:19:25Z, with spored active (PID 6670). journalctl -u spored: no entries.
shutting-down at 06:19:45Z, "User initiated (2026-10-31 06:19:45 GMT)": 78 s after SPAWN_COMPLETE.
So on-complete termination works, with ~1–1.5 min latency (the 30 s --completion-delay plus spored's poll). The run 5 case in the description ("still running 1 min 51 s after exit") was measured from the workload's exit line, not from SPAWN_COMPLETE, and I terminated it by hand prematurely. It's most likely not a bug. Run 4 (≥ 2 min 50 s, after a SIGTERM to a child) may be the same latency plus a slower trap. I didn't capture state there, so I can't say.
Remaining asks, smaller than the original:
Document the expected latency from command exit to shutting-down (delay + poll interval), so callers know when to stop waiting.
spored's own log: journalctl -u spored is empty. Where does it log? spawn logs covers the command log; saying where spored's lifecycle log lives would have answered this in one step.
changed the title [-]--on-complete terminate didn't fire within ~3 min of --command exit (exit 143 after SIGTERM to a child)[/-][+]Document on-complete termination latency (~1–1.5 min after --command exit) and where spored logs[/+]on Oct 31, 2026
Triage (2026-10-31, checked against origin/main): mostly docs, plus one real latency bug.
The completion path, from pkg/agent/agent.go:
The bootstrap writes /tmp/SPAWN_EXITCODE, then the completion file (pkg/launcher/bootstrap.go:1423, :1450-1453).
spored doesn't see the process exit. It polls on a 1-minute ticker (agent.go:588-593), after that tick's other work.
announceCompletion sleeps CompletionDelay, 30 s by default (:2225-2235).
terminate runs pre-stop, the task-record flush and Cleanup (DNS and plugins, 10 s timeouts), then sleeps 5 s (:2675).
It then runs checkRegionVacated, which blocks 60 s whenever no other spawn:managed instance is running in the region (:2680, :2693-2709). That is only for a region_vacated notification, but it runs even with no notifier configured, and it runs before Terminate.
Expected time from the completion file to terminate:
about 35–95 s with other spawn instances in the region;
about 95–155 s when it's the last one.
The tick phase (0–60 s) and the 60 s settle explain the inconsistency. Your 78 s run fits the first case.
The ≥ 2 min 50 s run is measured from the workload's exit line, so it adds time before the completion file is written. A plausible but unproven cause: the command runs as su … | tee and waits on PIPESTATUS (bootstrap.go:1419-1423), so a surviving descendant holding the pipe delays SPAWN_EXITCODE.
Logs: spored writes /var/log/spored.log, not the journal (cmd/spored/main.go:131-139). It's documented in docs/guides/logs.md:21 and reachable with spawn logs --which spored. Only a "not journalctl" note is missing.
Fix:
Bug, P2 (billed idle time): don't block Terminate on the region-vacated settle. Skip it when no notifier is configured, or run the check without delaying termination.
Docs: add the latency table and the 5 s and 60 s waits.
spored's own timeline (spawn 0.151.0, g7e.4xlarge in Local Zone us-west-2-lax-1b, Ubuntu 24.04 DLAMI, 2026-10-31). Answers this issue's 'where does spored log': /var/log/spored.log (plus /var/log/spawn-command.log); journalctl -u spored is empty.
/tmp/SPAWN_EXITCODE=2, /tmp/SPAWN_COMPLETE written 17:55:41.03Z
17:56:24 monitor tick 10
17:56:24 Completion signal detected: file /tmp/SPAWN_COMPLETE exists
17:56:24 Completion metadata: {"status": "failed", "exit_code": 2, "source": "command"}
17:56:24 Grace period: waiting 30s before action
17:56:54 Terminating instance (reason: Completion signal received)
17:56:55 ... DNS deleted ... Cleanup complete
17:56:55 Warning sent to users: TERMINATING NOW
So: detection latency is up to one 60 s monitor tick, plus the 30 s grace. New observation: EC2 still reported the instance running at 17:57:43Z, 49 s after spored logged 'Terminating instance' and 'Cleanup complete'. I then ran spawn terminate, and it went to shutting-down immediately. I can't tell from the log whether spored's TerminateInstances call failed, was throttled, or is just slow in a Local Zone: the log doesn't record the API result. Ask: log the TerminateInstances response (or error) and retry on failure. An earlier box in the same Local Zone (i-033c1f8b9c0156a20) did terminate on its own, ~5–6 min after exit.
Activity
scttfrdmn commentedon Oct 31, 2026
Correction with a measured case (2026-10-31, spawn 0.151.0, c8gd.16xlarge Spot, AL2023): this time I waited and captured state before doing anything.
/tmp/SPAWN_EXITCODE=0, written 06:18:27.368Z;/tmp/SPAWN_COMPLETEwritten 06:18:27.378Z. That's 18 s after the trap line, which was still syncing logs to S3.runningat 06:19:25Z, with spored active (PID 6670).journalctl -u spored: no entries.shutting-downat 06:19:45Z, "User initiated (2026-10-31 06:19:45 GMT)": 78 s after SPAWN_COMPLETE.So on-complete termination works, with ~1–1.5 min latency (the 30 s
--completion-delayplus spored's poll). The run 5 case in the description ("still running 1 min 51 s after exit") was measured from the workload's exit line, not from SPAWN_COMPLETE, and I terminated it by hand prematurely. It's most likely not a bug. Run 4 (≥ 2 min 50 s, after a SIGTERM to a child) may be the same latency plus a slower trap. I didn't capture state there, so I can't say.Remaining asks, smaller than the original:
shutting-down(delay + poll interval), so callers know when to stop waiting.journalctl -u sporedis empty. Where does it log?spawn logscovers the command log; saying where spored's lifecycle log lives would have answered this in one step.Retitling to match.
[-]--on-complete terminate didn't fire within ~3 min of --command exit (exit 143 after SIGTERM to a child)[/-][+]Document on-complete termination latency (~1–1.5 min after --command exit) and where spored logs[/+]scttfrdmn commentedon Oct 31, 2026
Triage (2026-10-31, checked against origin/main): mostly docs, plus one real latency bug.
The completion path, from
pkg/agent/agent.go:/tmp/SPAWN_EXITCODE, then the completion file (pkg/launcher/bootstrap.go:1423,:1450-1453).agent.go:588-593), after that tick's other work.announceCompletionsleepsCompletionDelay, 30 s by default (:2225-2235).terminateruns pre-stop, the task-record flush andCleanup(DNS and plugins, 10 s timeouts), then sleeps 5 s (:2675).checkRegionVacated, which blocks 60 s whenever no otherspawn:managedinstance is running in the region (:2680,:2693-2709). That is only for aregion_vacatednotification, but it runs even with no notifier configured, and it runs beforeTerminate.Expected time from the completion file to terminate:
The tick phase (0–60 s) and the 60 s settle explain the inconsistency. Your 78 s run fits the first case.
The ≥ 2 min 50 s run is measured from the workload's exit line, so it adds time before the completion file is written. A plausible but unproven cause: the command runs as
su … | teeand waits on PIPESTATUS (bootstrap.go:1419-1423), so a surviving descendant holding the pipe delaysSPAWN_EXITCODE.Logs: spored writes
/var/log/spored.log, not the journal (cmd/spored/main.go:131-139). It's documented indocs/guides/logs.md:21and reachable withspawn logs --which spored. Only a "not journalctl" note is missing.Fix:
Terminateon the region-vacated settle. Skip it when no notifier is configured, or run the check without delaying termination.Milestoned to v0.153.0.
docs(changelog): region-vacated check no longer delays termination (#…
fix(agent): region-vacated check never delays Terminate (#1456) (#1460)
scttfrdmn commentedon Oct 31, 2026
spored's own timeline (spawn 0.151.0, g7e.4xlarge in Local Zone
us-west-2-lax-1b, Ubuntu 24.04 DLAMI, 2026-10-31). Answers this issue's 'where does spored log':/var/log/spored.log(plus/var/log/spawn-command.log);journalctl -u sporedis empty.So: detection latency is up to one 60 s monitor tick, plus the 30 s grace. New observation: EC2 still reported the instance
runningat 17:57:43Z, 49 s after spored logged 'Terminating instance' and 'Cleanup complete'. I then ranspawn terminate, and it went toshutting-downimmediately. I can't tell from the log whether spored's TerminateInstances call failed, was throttled, or is just slow in a Local Zone: the log doesn't record the API result. Ask: log the TerminateInstances response (or error) and retry on failure. An earlier box in the same Local Zone (i-033c1f8b9c0156a20) did terminate on its own, ~5–6 min after exit.