Skip to content

Nothing reaps managed MPI security groups or placement groups (19 + 9 orphans found); --mpi creates an SG before validating its own flags #685

Closed

Description

@scttfrdmn

Found while cleaning up after real-hardware verification of #659/#668. Two related defects in the --mpi setup path, both "leave no trace" violations.

1. Managed MPI security groups and placement groups are never reaped

A single region of the dev account had accumulated 19 spawn-mpi-* security groups and 9 placement groups, all orphaned:

spawn-mpi-e2e-mpi-982369000     spawn-mpi-e2e-mpi-852789000
spawn-mpi-e2e-mpi-622276000     spawn-mpi-e2e-mpi-325891000
spawn-mpi-e2e-mpi-936579000     spawn-mpi-e2e-mpi-973261000
spawn-mpi-e2e-mpi-351237000     spawn-mpi-e2e-mpi-149201000
spawn-mpi-e2e-mpi-17169000      spawn-mpi-e2e-mpi-955058000
spawn-mpi-e2e-mpi-9217000       spawn-mpi-mpi-fixed
spawn-mpi-mpi-final             spawn-mpi-                   ← see (2)
… plus 5 from this session

Most predate this session — the e2e-mpi-* ones are from CI e2e runs — so nothing has ever cleaned them up. All 19 deleted without error once no instance referenced them, confirming they were pure orphans.

Neither is billable, which is why this went unnoticed, but both are real:

  • Security groups have a hard per-VPC quota (default 2500, but the rules quota and per-ENI limits bite sooner). An account running MPI e2e tests on a schedule accumulates these indefinitely until a launch starts failing for a reason that looks nothing like the cause.
  • spawn reaper reaps instances. Nothing reaps the scaffolding spawn creates around them. This is exactly the "who reaps the reapers" gap already noted for lambdas, roles, rules, alarms and the auto-created spawn-results-* buckets.

The placement-group cleanup that does exist (cleanupAbandonedPGs) is best-effort and deferred, and it loses the race on every failed cohort:

⚠️  could not delete abandoned placement group spawn-mpi-verifydrain-us-east-1a:
    InvalidPlacementGroup.InUse

It ran while instances were still shutting down. Termination is asynchronous, so a single immediate attempt will essentially always fail. It needs a short retry/backoff, or to be handed to the reaper.

Suggested shape: tag both resource kinds (spawn:managed=true, spawn:purpose=mpi-cluster — the SG already carries these) and have the reaper sweep tagged SGs and PGs with no referencing instance, on the same pass that reaps instances. That reuses the existing authority rather than adding a second cleanup path.

2. --mpi without --job-array-name creates a security group, then fails validation

$ spawn launch verify --instance-type c5n.9xlarge --count 2 --mpi --efa …
  ✅ Setting up IAM role (580ms)
{"operation":"create_security_group","instance_id":"spawn-mpi-","result":"success",
 "additional_data":{"security_group_id":"sg-05f971c6dd1d26daf"}}
--mpi requires --job-array-name

Two problems in four lines:

  1. An AWS resource is created before the arguments are validated. The launch then aborts and leaves the group behind. Argument validation must happen before anything is created — spawn gets this right elsewhere (--mpi on a non-cluster-capable instance type is refused up front, before spending, with a helpful message).
  2. The group is named spawn-mpi- — the empty job-array name interpolated into the template. Every such launch reuses that single group across unrelated clusters, so one spawn-mpi- group becomes a shared, self-referential all-traffic group for any future MPI launch that also skips the name. After --mpi --efa: auto MPI security group is TCP-only, so EFA cannot pass traffic; and it silently overwrites --security-group-ids #659 that group allows all protocols between its members, which makes accidental sharing worse than it was.

A name that is structurally impossible to collide on, or refusing the empty case, fixes (2); moving validation ahead of resource creation fixes (1).

Context

Both found while verifying #659 and #668 on real c5n.9xlarge and c6i.large launches. Related: #683 (the failed-cohort drain never terminated anything) and #684 (--mpi has never worked end-to-end, so these groups were all created for launches that could not have succeeded).

Activity

  1. added
    bug
    on Oct 4, 2026
  2. scttfrdmn commented on Oct 5, 2026

    @scttfrdmn
    ContributorAuthor

    #706 is merged. Four distinct defects turned out to be behind this, three of which I only found while fixing the first — recording the split so what remains is clear.

    Merged

    1. Ordering. validateMPIFlags ran ~286 lines after ensureSecurityGroup, so a launch that was about to be refused created a managed group first. The leftover was named spawn-mpi- — the prefix with an empty suffix — so every rejected attempt shared one group, which since #659 allows all protocols between its members. Validation needing no AWS call now runs before the first AWS mutation, and CreateOrGetMPISecurityGroup refuses a suffix-less name outright so the shared-group case is unreachable from anywhere, not just the CLI.

    2. The placement-group delete lost a race, every time. TerminateInstances is asynchronous and EC2 refuses to delete a group with members, so the delete issued right after a drain reported InvalidPlacementGroup.InUse and moved on. Now retried for up to 60s — short deliberately, because an empty placement group is free, so the only cost of giving up is quota pressure; blocking a CLI exit for minutes over a free resource is the worse trade. On giving up it prints the exact aws ec2 delete-placement-group command.

    3. The delete ignored the region entirely. Found while fixing (2) and strictly worse than it: CreatePlacementGroup pinned the client to the launch region, DeletePlacementGroup took no region and used the default one. A --region cohort created its group in one region and tried to delete it in another — InvalidPlacementGroup.Unknown, which is not retryable, so the group was abandoned on the first attempt however long the retry waited. The retry in (2) could never have saved those. A same-named group genuinely present in the default region would have been deleted instead. The region is now a required parameter, and a gate rejects any regional EC2 call in pkg/aws built on the default-region config, since that shape is the bug rather than this one instance of it.

    4. Nothing could see the orphans. spawn tags every placement group spawn:managed=true, but the Resource Groups Tagging API — which DiscoverManagedResources is built on — does not return placement groups at all. So spawn orphans, spawn cleanup and spawn resources were all blind to them: nine orphans in one region of one account, findable only with aws ec2 describe-placement-groups. They are now scanned separately, like Elastic IPs.

    Worth stating one judgement in (4): orphan-ness is per group, not per region. An MPI cohort creates one group per AZ it tries, so a cohort that fell back from one AZ to another leaves the abandoned AZ's group genuinely empty while its own instances are running. The region-wide rule used for the shared security group and key pair would have hidden exactly the leak this exists to find.

    Still open — and one is a different issue

    The MPI security group. Unchanged, and still deliberately durable: it is keyed on spawn-mpi-<job-array-name> and reused by name across runs, which is why CreateOrGetMPISecurityGroup is a get-or-create and why #659's rule backfill exists. "Delete it when the cohort finishes" would therefore be wrong — it would force a recreate on every repeat run of the same named array. That makes it reaper territory, and it still needs the two calls I asked for before: whether the sweep lives in the reaper Lambda (a deploy, and the last two reaper deploys each caused an incident) and what age threshold is right.

    A separate blocker I hit while verifying (4): spawn orphans reports nothing by default, in an account holding 21 orphans. --mine filters on spawn:iam-user, which spawn never writes to shared infrastructure, so a missing tag does not narrow the result — it empties it. Filed as #708. Until that is resolved, (4) only pays off with --all, which undercuts the fix: the placement-group sweep sidesteps it by not applying the filter at all, but that inconsistency is itself part of what #708 has to settle.

    Leaving this open on the security-group half.

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