Skip to content

fix: Provision tears down instance on post-launch failure (#220) - #230

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/220-provision-post-launch-cleanup
Jun 24, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/220-provision-post-launch-cleanup

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #220.

The real root cause (not the reported one)

I traced #220 exhaustively — static (against the v0.61.0/v0.62.0 tags) and live in 942542972736/us-west-2. The issue hypothesized a pre-launch FSx-ordering regression ("CreateFileSystem per-AZ before RunInstances"). That is not what v0.62.0 does — #213 genuinely reordered create-to-after-launch, and a live repro confirmed a RunInstances failure creates zero FSx.

The actual bug is post-launch abandonment:

  • RunInstances succeeds → instance is running.
  • A post-launch step (ephemeral FSx setup) fails.
  • Provision returned (nil, err) — without terminating the running instance.
  • → orphaned billable instance. And under lagotto's per-AZ retry loop (launchAcrossAZs), the caller treats the error as a failed attempt and launches another instance in the next AZ, orphaning one instance (+ any FSx created before the sub-failure) per AZ — exactly the "3 orphans per capacity burst, ~1 per AZ" pattern reported.

Live proof (before → after), cheap t3.micro, cleaned up

Forced a real post-launch failure (valid launch, invalid FSx capacity):

  • Before fix: Provision errored; leak-check found instance i-0f5c… running (orphaned) — terminated manually.
  • After fix: same scenario → post-launch provisioning failure: FSx setup failed, terminated instance i-0fe9… to avoid a leak; leak-check clean (instance terminated, zero FSx).

Fix

  1. Provision terminates the just-launched instance on any post-launch failure — a partial provision leaves nothing billable (FSx auto-create: explicit lifecycle contract (ephemeral|durable), fail-closed, + canonical docs #193 fail-closed contract, extended past RunInstances). The existing FSx-create function already deletes a created-then-untaggable FSx; the two cleanup paths compose.
  2. New launcher.ErrPostLaunch sentinel wrapping these failures, so AZ/region-retry callers can classify them terminal (the launch worked — retrying churns launch+terminate). lagotto's ClassifyFailure will key on this (companion lagotto PR).

Tests

  • TestProvision_NoFSxOrphanOnLaunchFailure — substrate-backed, verified non-vacuous (substrate does track FSx creates): a RunInstances failure creates zero FSx.
  • Live before/after proof (above).
  • make check clean.

Note on the reaper

The deployed ttl-reaper would eventually catch these (ephemeral-orphan net), but it doesn't run in end-user accounts (lagotto#29) — so for the beta accounts hitting this, Provision's own cleanup is the only backstop. That's why the fix belongs here.

Root cause of #220 (verified live, not the reported pre-launch-ordering
hypothesis): when RunInstances SUCCEEDS but a post-launch step fails (ephemeral
FSx setup), Provision returned (nil, err) WITHOUT terminating the now-running
instance. That orphans a billable instance — and under lagotto's per-AZ retry
loop, the caller treats it as a failed attempt and launches ANOTHER one,
orphaning one instance (+ any FSx created before the sub-failure) per AZ. That
matches the observed '3 orphans per capacity burst, ~1 per AZ' far better than
the pre-#213 ordering (which #213 already fixed and which a live repro confirmed
creates zero FSx on a RunInstances failure).

Fix:
- On any post-launch failure, terminate the just-launched instance so a partial
  provision leaves nothing billable (the #193 fail-closed contract now extends
  past RunInstances). Verified live in 942542972736/us-west-2: the scenario that
  orphaned a t3.micro now auto-terminates it; leak-check clean.
- New launcher.ErrPostLaunch sentinel wrapping these failures, so AZ/region-retry
  callers (lagotto launchAcrossAZs) can treat them as terminal instead of
  re-launching into the same downstream failure.

Tests: TestProvision_NoFSxOrphanOnLaunchFailure (zero FSx on RunInstances
failure, substrate-backed + non-vacuous) + the live before/after proof.
Refs #220, #210, #213.
@scttfrdmn
scttfrdmn force-pushed the fix/220-provision-post-launch-cleanup branch from 501453d to 56786c8 Compare June 24, 2026 15:36
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
pkg/launcher/provision.go 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

…odule

The lambda/dns-updater submodule still pinned x/net v0.52.0, which newly-published
HIGH CVEs (CVE-2026-25680/25681/27136/33814/39821/42502/42506 — HTML-parse DoS,
HTTP/2 DoS, IDNA priv-esc) now flag, failing the Trivy gate. The main module is
already on v0.55.0; this brings the submodule in line. Incidental to #220 (the
fix is in pkg/launcher) but bundled to keep this PR's CI green.
@scttfrdmn
scttfrdmn merged commit 158b506 into main Jun 24, 2026
6 of 7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/220-provision-post-launch-cleanup branch June 24, 2026 15:44
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