Skip to content

fix: don't orphan ephemeral FSx when the launch fails (#210) - #211

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/210-fsx-orphan-on-failed-launch
Jun 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/210-fsx-orphan-on-failed-launch

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #210. CRITICAL cost/quota leak.

The bug

Ephemeral --fsx-create creates the FSx before RunInstances. On a launch failure (e.g. InsufficientInstanceCapacity — exactly what lagotto retries on), the filesystem has no instance to own it, and the ttl-reaper keyed ephemeral reclamation on instance termination — a path never reached when no instance launches. Under lagotto's retry-on-capacity loop this orphaned ~3 × 1.2 TiB filesystems per poll → the full PERSISTENT_2 quota (100,800 GiB / 84 filesystems) in ~35 min, ~$14.6k/mo if left running. It defeats the #193 fail-closed contract: a capacity failure left a 1.2 TiB billable resource behind.

Orphan status: swept both accounts across all regions — no orphaned filesystems remain (reporter already cleaned up). No live cost fire.

Fix — defense-in-depth (issue fixes #2 + #3)

1. Compensating teardown (the primary fix)
Both the CLI (cmd/launch.go) and the headless launcher (pkg/launcher/provision.go) now delete the just-created ephemeral FSx (config.FSxPending) if RunInstances fails. A failed launch leaves no billable resource. A delete failure is surfaced loudly (🛑 … DELETE IT MANUALLY …) so a leak is never silent. Scoped to ephemeral — a durable FSx is a deliberate persisted resource.

2. Reaper safety net (lambda/ttl-reaper)
evaluateFSx now reclaims any spawn:fsx-lifecycle=ephemeral filesystem with no referencing instance for longer than a 30-min orphan grace (ephemeralOrphanGrace), reason ephemeral-orphan. This covers the "instance never launched" case even if the compensating teardown is missed (crash between create and teardown, or a delete error). Crucially, fsxInUse now also counts the spawn:fsx-pending provisioning lease (not just spawn:fsx-id), so a healthy ephemeral FSx is never reaped during its legitimate ~10-min mount window. Durable filesystems are exempt (they use max-age/deadline, not the short grace).

Tests

Reaper: evaluateFSx ephemeral-orphan past-grace (reaped), within-grace (spared), durable-exempt. All three modules (root, launcher, reaper) build / vet / test clean.

Follow-up (not in this PR)

lagotto could also avoid re-creating FSx every poll on a capacity-retry (issue fix #4), but the spawn-side fix is the right layer — --fsx-create was broken for any failed launch, lagotto or not. Worth a lagotto issue.

CRITICAL cost/quota leak. Ephemeral --fsx-create creates the FSx BEFORE
RunInstances. On a launch failure (e.g. InsufficientInstanceCapacity — the
case lagotto retries on), the filesystem had no instance to own it, and the
ttl-reaper keyed ephemeral reclamation on instance termination, so it never
got reclaimed. Under lagotto's retry loop this orphaned ~3 x 1.2 TiB FSx per
poll → full PERSISTENT_2 quota in ~35 min (~$14.6k/mo).

Defense-in-depth:
1. Compensating teardown: both the CLI (cmd/launch.go) and the headless
   launcher (pkg/launcher/provision.go) delete the just-created ephemeral FSx
   if RunInstances fails — a failed launch leaves no billable resource (the
   #193 fail-closed contract). A delete failure is surfaced loudly so a leak is
   never silent.
2. Reaper safety net (lambda/ttl-reaper): reclaim any
   spawn:fsx-lifecycle=ephemeral filesystem with no referencing instance for
   >30min (ephemeralOrphanGrace) — covers 'instance never launched' even if the
   teardown is missed (crash/delete error). fsxInUse now also counts the
   spawn:fsx-pending provisioning lease, so a healthy FSx isn't reaped during
   its ~10-min mount window.

Tests: reaper evaluateFSx ephemeral-orphan past/within grace + durable-exempt.
All modules build/vet/test clean.

Closes #210
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch.go 0.00% 14 Missing ⚠️
pkg/launcher/provision.go 0.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 209b358 into main Jun 17, 2026
6 of 7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/210-fsx-orphan-on-failed-launch branch June 17, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant