Skip to content

spawn launch: InvalidInstanceID.NotFound immediately after RunInstances succeeds (EC2 eventual consistency) #78

Closed

Description

@scttfrdmn

Summary

spawn launch calls RunInstances, gets back a successful response with an instance ID, then immediately calls DescribeInstances on that ID — which returns InvalidInstanceID.NotFound (HTTP 400). The launch exits 1 even though the instance was created and is running.

Reproduction

This surfaces reliably when spawn launch is called from within an EC2 instance (nested spawn, e.g. via nf-spawn dispatching Nextflow tasks), but can also happen from any caller when the DescribeInstances call races EC2 API propagation.

From the spawn launch log captured on a head node:

{"timestamp":"...","level":"info","operation":"launch_instance","instance_id":"i-0e61513d099a3f99c","result":"success",...}
❌ Error: failed to describe instance: operation error EC2: DescribeInstances,
   https response error StatusCode: 400, RequestID: 9844b2e2-763b-44ba-8987-f71d5d5d6ab7,
   api error InvalidInstanceID.NotFound: The instance ID 'i-0e61513d099a3f99c' does not exist

The instance i-0e61513d099a3f99c was successfully created — it appeared in aws ec2 describe-instances seconds later and ran to completion. The launch JSON log confirms "result":"success".

Root cause

EC2's RunInstances and DescribeInstances are eventually consistent. After a successful RunInstances, a subsequent DescribeInstances for the new instance ID can return InvalidInstanceID.NotFound for a few seconds while EC2 propagates the new instance across its internal systems. This is documented AWS behavior.

The fix is to retry DescribeInstances with exponential backoff when InvalidInstanceID.NotFound is returned in the post-launch window, rather than treating it as a hard failure. The AWS SDK v2 ec2.NewInstanceRunningWaiter handles pending → running transitions but does not automatically retry on a NotFound 400 — that must be handled explicitly.

Impact

  • Causes spawn launch to exit 1 and fail the caller (nf-spawn marks the task as failed and aborts the Nextflow run)
  • The leaked instance continues running with its TTL, but the user's workload is lost
  • Reproducible from nested launch paths (instance → spawn launch → EC2) where propagation seems slower than direct CLI usage

Suggested fix

In the post-launch DescribeInstances / --wait-for-running path: catch InvalidInstanceID.NotFound and retry with backoff (e.g., 1s, 2s, 4s up to ~30s) before treating it as a fatal error. This is a standard pattern for post-RunInstances polling.

Context

Activity

  1. scttfrdmn commented on Jun 8, 2026

    @scttfrdmn
    ContributorAuthor

    Fixed in #81, released as v0.37.2. DescribeInstanceWithRetry now retries InvalidInstanceID.NotFound (and the empty-result race) with capped backoff (~30s) before failing, applied to GetInstancePublicIP/GetInstanceState, WaitForRunning (which pre-absorbs the window since the SDK running-waiter doesn't retry a NotFound 400), and the queue connect path. nf-spawn nested launches should no longer abort on the post-RunInstances propagation race — worth confirming with a microbiome-demo rerun on a spawn ≥ v0.37.2.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions