Skip to content

ttl-reaper leaks Route53 DNS records: must delete DNS when reaping an instance #247

Closed

Description

@scttfrdmn

Summary

When the ttl-reaper terminates a stray/expired instance, it does not delete that instance's Route53 DNS record, so every reaper-terminated (or otherwise non-gracefully-stopped) instance leaks an A record into spore.host. DNS cleanup only happens in spored's graceful shutdown (Cleanup → DeleteDNS); the reaper is precisely the path that fires when graceful shutdown didn't run, so the record is guaranteed orphaned.

Evidence

The live spore.host zone currently holds 61 instance A-records (76 total − 15 infra records), almost all e2e-*/test throwaways from past runs, while the dev account has zero running spawn-managed instances. They're orphans — terminated instances whose records were never cleaned up.

Root cause

lambda/ttl-reaper/main.go:

  • evaluate() (line ~437) reads the spawn:dns-name tag only to label the candidate for logging — name = tags[tagprefix.Tag("dns-name")].
  • the reap action calls ec2:TerminateInstances and never touches Route53.
  • template.yaml IAM grants ec2:TerminateInstances (+ FSx) but no route53:* — so even if the code tried, it couldn't.

spored's DeleteDNS runs in pkg/agent Cleanup() on SIGTERM, but a reaped instance is terminated out from under the daemon, so that path doesn't run.

Fix

When the reaper terminates an instance that carries a spawn:dns-name tag, also delete its Route53 records (the base36 A record and, if spawn:account-name is present, the alias CNAME) — mirroring what spored's graceful DeleteDNS/DeleteJobArrayDNS does. Requires:

  • reaper logic: after a successful (non-dry-run) terminate, issue the Route53 delete for the instance's FQDN(s). Best-effort + logged; a missing record is not an error.
  • IAM (template.yaml): add route53:ChangeResourceRecordSets + route53:ListResourceRecordSets scoped to the hosted zone(s). The reaper runs in the infra account where the zone lives, so this is same-account (no cross-account hop needed for the Route53 call).
  • honor REAPER_DRY_RUN (log "WOULD delete DNS …").

Consider sharing the FQDN-construction + delete logic with the dns updater / pkg/dns so the base36 encoding stays consistent.

Cleanup of existing orphans

Separately, the ~61 existing stale records should be swept once (a one-off, or a reaper "orphan DNS" pass that deletes records whose IP no longer maps to a running managed instance). Filing that as part of this or a follow-up is fine.

Refs

Lifecycle invariant ("everything dies eventually" — and shouldn't leak). Related: the reaper FSx-cleanup path (#192/#212) is the precedent for the reaper owning downstream-resource cleanup, not just the instance.

Activity

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

    @scttfrdmn
    ContributorAuthor

    Design refinement: the reaper must do teardown MANUALLY, not delegate to spored

    Key principle (clarifying the fix direction): the reaper is a backstop that only runs when spored failed — dead, wedged, IMDS-blocked, crashed, or never started (the #65 class). So the fix is NOT "have the reaper trigger spored's graceful Cleanup→DeleteDNS": that asks the already-broken daemon to do the cleanup. By the time the reaper fires, we must assume spored is gone and perform every downstream cleanup out-of-band, from the reaper itself.

    This is the same ownership model the reaper already uses for FSx (#192/#212): it deletes the filesystem directly rather than relying on spored. DNS should follow suit.

    So the reaper's terminate path becomes a full manual teardown:

    1. (already, ttl-reaper terminates without running --pre-stop (out-of-band path bypasses the flush) #187, REAPER_GRACEFUL=true) best-effort pre-stop flush via SSM — but ONLY because the box might still be reachable; treat success as a bonus, never a precondition.
    2. (this issue) delete the Route53 record(s) directly — base36 A + alias CNAME — via a Route53 call from the infra account. Do NOT route this through spored.
    3. terminate the instance (existing).
    4. (existing) FSx cleanup.

    All best-effort + REAPER_DRY_RUN-aware + logged; a missing record / unreachable box never blocks the terminate.

    Why not "wake spored to self-clean"

    Considered and rejected: it inverts the backstop contract. If spored were healthy enough to gracefully clean up, the deadline would already have been enforced and the reaper would never have selected this instance. Relying on the dead daemon is the bug, not the fix.

    Net: the reaper construct already deletes the IP→record after-the-fact; the FQDN is derivable from spawn:dns-name (+ spawn:account-name for the alias) + the account id (base36), so no spored round-trip is needed.

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