Skip to content

CRITICAL: spored monitor loop never runs after startup — TTL/idle/on-complete/pre-stop all silently dead #65

Closed

Description

@scttfrdmn

Severity: critical — breaks the core lifecycle + cost-control guarantee

On a freshly launched instance, spored logs Monitoring started and then nothing ever again — the monitor's per-minute checkAndAct loop never executes. Consequently none of these fire:

Evidence (real instance, spawn/spored v0.36.11)

Launched --on-complete stop --completion-delay 5s --pre-stop "touch /tmp/prestop-ran.txt". Full /var/log/spored.log, unchanged across ~10 min and multiple completion triggers:

... 03:48:30 Agent initialized for instance i-... 
03:48:30 Config: TTL=20m0s, IdleTimeout=0s, Hibernate=false
03:48:30 ... Monitoring started
03:48:30 EBS hourly cost: $0.0022/hr

Last line is 03:48:30. Touched /tmp/SPAWN_COMPLETE repeatedly; instance stayed running indefinitely; /tmp/prestop-ran.txt never created; checkAndAct's config-refresh (which logs warnings on failure) never logged. Daemon is active (systemctl) — alive but its monitor loop body never runs.

Two corroborating facts:

  • The startup Config: line shows TTL=20m but no on-complete — the daemon read tags before spawn:on-complete was visible (eventual consistency). That alone would be handled by the tick-1 config refresh (agent.go:262, configRefreshTick == 1) — except that refresh never runs, which is the real bug.
  • A separate spored config list process (fresh agent) DOES read on-complete/pre-stop correctly — so tags & parsing are fine; it's specifically the daemon's running monitor that's stuck.

Suspected cause

Agent.Monitor (pkg/agent/agent.go:219): after log.Printf("Monitoring started") (223) and BEFORE the ticker for-loop (245), it calls a.provider.IsSpotInstance(ctx) (228). IsSpotInstance (pkg/provider/ec2.go) does a blocking IMDS GetMetadata("instance-life-cycle") with the daemon's context (no per-call timeout). If that IMDS call hangs (IMDS hop-limit, token, or network), Monitor blocks before ever entering the ticker loop — exactly the observed "logs started, then dead" behavior.

Fix direction

  1. Give IsSpotInstance (and the other IMDS calls) a short per-call timeout (e.g. context.WithTimeout(ctx, 5s)) so it can never block startup. On timeout, assume not-spot and proceed.
  2. Better: move the spot-monitor goroutine launch to NOT gate the main ticker loop — start the ticker loop first, decide spot-monitoring asynchronously.
  3. Add a heartbeat log to checkAndAct (e.g. trace-level every tick) so a dead loop is observable.

Impact / why critical

An instance whose monitor is dead never auto-terminates on TTL → unbounded cost, the core thing spore.host exists to prevent. Likely also the root cause behind nf-spawn pre-stop/on-complete reports and several Tier 2 e2e failures (#61). The e2e reaper/leak-check only protect the test account — real users have no such safety net.

Context

Found debugging #61 Tier 2 pre-stop failure on real AWS. Reproduces every launch. Needs IMDS-readiness verification on the instance to 100% confirm the IsSpotInstance hang, but the evidence strongly points there.

Activity

  1. added
    bug
    on Jun 6, 2026
  2. scttfrdmn commented on Jun 6, 2026

    @scttfrdmn
    ContributorAuthor

    Root-caused and fixed in #67. Confirmed on real AWS (spore-host-dev, t3.small):

    • Baseline (stock spored v0.36.11): logged "Monitoring started" then silent for 4+ min — the 1-min ticker fired 0 times; instance never acted on TTL/completion. Bug reproduced exactly.
    • With fix: monitor ticked 11×, one per minute (monitor tick N heartbeat). Lifecycle loop runs unconditionally; IsSpotInstance now off the critical path + bounded to 5s.

    Fix: spot detection/polling moved to its own goroutine so it can't gate the ticker loop; IsSpotInstance/CheckSpotInterruption bounded with context.WithTimeout(5s); per-tick heartbeat log added. Regression test TestMonitor_SpotDetectionDoesNotGateTicker fails against the old gating code, passes with the fix.

    Note: a sibling bug #66 (PrivateTmp hid the completion file) had to be fixed too before on-complete/pre-stop actually fired end-to-end.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions