Skip to content

Back off a failed idle stop, announce only success, and restore DNS on failure (#948) - #977

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/948
Oct 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/948

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #948. Stacked on #969 (fix/952) → #960 → #955 → #936. The base is fix/952, so the diff shows only #948.

What was wrong

When the idle timeout was reached, checkAndAct sent idle_stopped before calling stop(). stop() then ran cleanup (DNS deletion, plugin stop, registry deregistration), warned users, and only logged a StopInstances failure. On the next tick the instance was still idle and past the timeout, so the whole sequence ran again, once a minute until TTL. Each run sent another false idle_stopped and deleted the DNS name of an instance that was still running.

The issue also says the pre-stop hook re-ran on each attempt. It does not: runPreStop is already guarded by preStopDone, and the task flush by taskFlushDone, so this PR leaves both alone.

What changed

  • idleTimeoutReached now owns the idle action:
    • idle_stopped / idle_hibernated are sent only after the provider call succeeds.
    • A failure sends one idle_stop_failed with the error. It sets a backoff of 5, 10, 20 and 40 minutes, then hourly (idleActionRetryDelay). Ticks inside the backoff do nothing.
  • stop() / hibernate() return the provider error. On failure they call restoreAfterFailedStop, which:
    • re-registers the hybrid-registry entry;
    • makes the DNS lease due and runs refreshDNSLease, so the deleted record is registered again through the same path as renewal, and spawn:dns-status records a failure if that re-registration fails.
  • Cleanup still runs before the EC2 call. The other option was to stop first and clean up only on success. I rejected it because a hibernating guest is frozen rather than shut down, so it would never get its SIGTERM-path cleanup.
  • The on-complete stop / hibernate paths get the DNS restore too, because it lives in stop() / hibernate().
  • Test seams: Notifier.record (synchronous event capture), stubProvider.stopErr / hibernateErr with call counts, and Agent.warnDelay for the 5 s user-warning sleep.

Tests (pkg/agent/idle_stop_retry_test.go)

  • TestFailedIdleStopBacksOffAndIsNotAnnouncedAsStopped (stop and hibernate): ten idle one-minute ticks against a provider returning EC2's one-time-Spot UnsupportedOperation. Expected: 2 attempts, 0 idle_stopped/idle_hibernated, exactly 1 idle_stop_failed.
  • TestSuccessfulIdleStopIsAnnounced.
  • TestIdleActionRetryDelay: the schedule and its cap.
  • TestFailedStopRestoresDNS: a real dns.Client against an httptest updater. A failed stop or hibernate gives [DELETE UPSERT]; a successful stop gives [DELETE].

Revert checks. Each revert compiled (go vet clean), and the test ran and failed:

revert failure
ignore the backoff "10 stop attempts in 10 idle minutes, want 2" (stop and hibernate)
notify before checking the result (the old order) "idle_stopped" sent 2 times although nothing stopped (and idle_hibernated)
no DNS restore DNS actions = [DELETE], want [DELETE UPSERT]
notify on every failure idle_stop_failed sent 2 times over two failures, want once

go test -race ./pkg/agent passes, and the whole pkg/agent suite passes on Linux (an arm64 test binary run in an AL2023 container). make check passes except for the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker. make check-nested passes: all 9 modules are clean.

Caveats

@scttfrdmn
scttfrdmn changed the base branch from fix/952 to main October 17, 2026 08:46
…n failure (#948)

A failed StopInstances (one-time Spot, missing ec2:StopInstances) was only
logged, so the next idle tick ran the whole stop again: once a minute until
TTL, each time sending `idle_stopped` for a running instance and deleting
its DNS name again.

- idleTimeoutReached owns the idle action. It sends idle_stopped /
  idle_hibernated only after the provider call succeeds. A failure sends one
  idle_stop_failed with the error and sets a backoff of 5, 10, 20, 40
  minutes, then hourly (idleActionRetryDelay); ticks inside the backoff do
  nothing.
- stop() and hibernate() return the provider error. On failure they call
  restoreAfterFailedStop, which re-registers the hybrid-registry entry and
  makes the DNS lease due so the record Cleanup deleted is registered again
  (through the same path as the renewal, so spawn:dns-status stays honest).
  Cleanup still runs before the EC2 call: a hibernating guest is frozen,
  not shut down, and gets no later chance to deregister.
- The pre-stop hook was already run-once (preStopDone); unchanged.
- Test seams: Notifier.record, stubProvider stopErr/hibernateErr and call
  counts, and Agent.warnDelay for the 5s user-warning sleep.

(#948)
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/agent.go 87.03% 6 Missing and 1 partial ⚠️
pkg/agent/notifier.go 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 7e96bab into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/948 branch October 17, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spored repeats a failed idle stop every minute: pre-stop hook, DNS teardown and an 'idle_stopped' notification each time

1 participant