Skip to content

After a resume from hibernation spored carries its pre-hibernate state: no pre-stop hook on the next stop, no DNS name, and the idle timer already expired #987

Closed

Description

@scttfrdmn

Found while fixing #948/#952 (PRs #977, #969). Verified by reading pkg/agent/agent.go and the systemd units; not reproduced on an instance.

A stopped instance boots a fresh spored. A hibernated instance resumes the same process, with all its memory, and nothing in spored or its units handles the resume. There is no sleep.target or hibernate.target hook and no resume detection. So, after --hibernate-on-idle (or --on-complete hibernate) and a spawn start / spawn connect:

  1. The pre-stop hook never runs again. runPreStop sets preStopDone = true and nothing resets it. The next hibernate, stop or TTL terminate skips the user's hook (for example aws s3 sync) and flushTaskRecord (taskFlushDone). That is the data-loss shape of --pre-stop does not reliably flush before TTL-triggered terminate → data loss on ephemeral storage #184/pre-stop: surface a loud signal when the hook transfers nothing / exits non-zero #186.
  2. The DNS name is gone and comes back with the wrong IP. Cleanup deleted the record before hibernating. Nothing re-registers it until the hourly lease renewal, and that renewal uses a.identity.PublicIP cached from the first boot, but a resumed instance without an EIP has a new public IP.
  3. The idle timer has already expired. lastActivityTime is from before the hibernation, so the first idle tick after resume finds idleTime >= IdleTimeout and hibernates again within about a minute, unless something shows activity first. An SSH login does, through its fresh PTY (Linux idle check: any /dev/pts entry or still-open login blocks idle-stop forever, defeating countActiveSessions' 'idle SSH sessions don't block' design #953), but a spawn start with no login does not. idleWarned is also still set, so the 5-minute warning is skipped.

Related: #945 (the compute clock counts the hibernated time).

Suggested fix: detect the resume, either with a systemd sleep.target / systemd-sleep post hook that signals spored, or by seeing a wall-clock jump much larger than the monotonic tick interval. On resume: reset preStopDone, taskFlushDone, lastActivityTime and idleWarned; re-read the identity from IMDS (the public IP); re-register DNS; and take fresh counter baselines. Restarting spored on resume (Restart from a sleep hook) would get all of that from the normal boot path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions