Skip to content

spawn resume: region-from-defaults type assertion panics if params file has no region default #495

Description

@scttfrdmn

Context

Found while implementing #494 (spawn resume --max-concurrent-auto), which needs a reliably-set region — this bug sits directly upstream of that.

cmd/resume.go's region-resolution logic:

region := ""
for _, inst := range state.Instances {
    if inst.InstanceID != "" {
        region = paramFormat.Defaults["region"].(string)
        break
    }
}
if region == "" {
    region = "us-east-1" // Default
}

The bug

paramFormat.Defaults["region"].(string) is an unchecked (non-, ok) type assertion. If the sweep's original parameter file has no top-level region in defaults (e.g. every param set set its own region individually, or the sweep only ever used the CLI's --region flag rather than a param-file default), Defaults["region"] is nil, and nil.(string) panics rather than falling through to the region == """us-east-1" fallback below it.

The panic is reachable only when state.Instances has at least one entry with a non-empty InstanceID (i.e. at least one instance was actually launched before the sweep was interrupted) AND the param file's defaults map has no region key or a non-string one — otherwise the loop body never runs and the region == "" fallback below correctly applies.

Ask

Use the checked form (region, _ = paramFormat.Defaults["region"].(string)), or better, derive region the same way the rest of the per-config logic already does (buildLaunchConfigFromParams's per-entry region, falling back through defaults) rather than reaching into Defaults directly and assuming a top-level scalar. Worth checking whether state.Instances[i]'s own recorded config/tags could just carry the region it actually used, removing the guesswork entirely.

Not filed as blocking anything — spawn resume's existing --max-concurrent path has lived with this since before #492/#494; flagging it now because #494's --max-concurrent-auto makes correctness of region matter more (a wrong/panicked region means a wrong quota answer, not just a wrong ListInstances region filter).

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