Skip to content

fix(launch): make the SSH-readiness result reportable, and gate DNS on it (#740, #741) - #742

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/740-ssh-readiness-gate
Oct 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/740-ssh-readiness-gate

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #740. Closes #741.

Both halves of the stall the reporter captured with a SIGQUIT watchdog. They ship
together because #741's fix is #740's return value — the gate has nothing to
gate on until the probe can fail.

#740 — the failure was not dropped, it was unrepresentable

func waitForSSHReady(ctx context.Context, host string, timeout time.Duration) {

No return value. The timeout path and the success path were the same return
statement. The caller then called prog.Complete("Waiting for SSH")
unconditionally, so an unreachable instance printed:

02:52:49   ✅ Waiting for SSH (120.0s)

120.0s to the tenth of a second is the deadline, rendered as success.

Nothing downstream caught it either, and that is the part worth dwelling on:
the next gate verifies spored over SSM, which was working. The instance was
healthy, spored was up, and the one broken thing was the one signal being
discarded. Then the launch SSHed to that host for another four minutes.

Now the probe returns an error naming the host and the dial failure — "refused"
and "timed out" are different diagnoses and the user needs to know which. The
launch reports it and stays non-fatal: the instance is running and spored is
enforcing TTL/idle/cost, so failing here would destroy a working spore over a
connectivity problem. It points at spawn connect, which already falls back to
SSM.

The gate already existed. --wait-for-ssh=false skips DNS registration, with
the reasoning spelled out in its own comment — "we cannot and should not register
a record pointing at an instance whose reachability is unconfirmed"
. Identical
reasoning, simply unreachable for the case where we did wait and it failed. This
makes it reachable.

Also: a launch with no public IP skipped the probe and still printed ✅. Same false
claim by a different route; now it says what it skipped and why.

#741 — three compounding problems in the retry

problem consequence
budget checked only between attempts, exec.Command has no context one ssh that connects then hangs outlives the four-minute deadline entirely — ConnectTimeout=10 caps only the TCP connect
predicate was err != nil every failure counted as a transient early-boot race, so an unreachable host spent the full budget on ~16 attempts that could not succeed
caller's context not threaded Ctrl-C did not reach the child

sshRegisterRetryable now distinguishes the races the retry was actually written
for — Permission denied (publickey) before cloud-init writes authorized_keys,
and curl exit 6/7/28 from an instance whose resolver is not yet up, both of
which a fresh session genuinely recovers — from reachability failures, which no
fresh session can fix.

An unrecognised message stays retryable on purpose: a wording we have not seen
should degrade to the old behaviour, not cause a new class of premature give-up.
The failure mode of being too eager to retry is a slow launch; of being too eager
to stop, a broken one.

Verification

Gates confirmed to fail when reverted:

revert fails
timeout returns nil waitForSSHReady returned nil for an unreachable host — the caller cannot tell this from success, which is exactly #740
restore err != nil as the predicate sshRegisterRetryable = true, want false — a fresh session reaches the same refusing host — this is #741's four wasted minutes

The first version of the timeout test passed against the broken code. It
probed 127.0.0.1, and this machine runs sshd — waitForSSHReady hardcodes
port 22, so the dial succeeded and returned nil legitimately. "Unreachable" has to
be unreachable for the probe's port, not for a port I picked. Now uses
203.0.113.1 (TEST-NET-3, RFC 5737). Recorded in the test comment, because the
next person writing a port-22 test will reach for loopback too.

gofmt, go vet ./..., go test -short ./..., make check-docs, changelog
gate, semgrep scan --config=auto --error (0 findings).

Not in this PR

Why SSH was unreachable in us-west-1 remains open. Two obvious explanations are
ruled out and recorded in #740: the default VPC there has an IGW with
MapPublicIpOnLaunch=true on every subnet, and the spawn-managed port-22 ingress
rule left in that region matches the controller's current public IP exactly. It
needs a live instance there to settle, and none of these fixes depend on it.

…n it

Reproduced from a goroutine dump: a launch that succeeded then sat for
six minutes in registerDNS -> exec -> ssh, SSHing to a host whose SSH
port had already failed to answer, printing nothing.

#740, the root cause: waitForSSHReady RETURNED NOTHING. The timeout path
and the success path were the same statement, so the failure was not
dropped — it was unrepresentable. The caller then called
prog.Complete("Waiting for SSH") unconditionally, so an unreachable
instance printed `✅ Waiting for SSH (120.0s)`: the timeout, to the tenth
of a second, rendered as success.

Nothing downstream caught it either. The next gate verifies spored over
SSM, which was working — so the instance was healthy, spored was up, and
the single broken thing was the single signal being discarded.

- waitForSSHReady returns an error naming the host and the dial failure
  (refused vs timed out are different diagnoses).
- The launch reports it and stays non-fatal: the instance is running and
  spored is enforcing TTL/idle/cost, so failing here would destroy a
  working spore over a connectivity problem. It points at `spawn connect`,
  which falls back to SSM.
- It now GATES DNS registration, which registers over SSH. That skip
  already existed for --wait-for-ssh=false, with the reasoning in a
  comment — "we cannot and should not register a record pointing at an
  instance whose reachability is unconfirmed" — and was unreachable for
  the case where we DID wait and it failed.
- A launch with no public IP no longer claims to have checked SSH.

#741, the time cost, two fixes in the retry itself:

- The four-minute budget was checked only BETWEEN attempts and the exec
  had no context, so one ssh that connected and then hung outlived the
  deadline (ConnectTimeout=10 caps only the TCP connect). The budget now
  binds every attempt via CommandContext, and the caller's ctx is
  threaded through so a Ctrl-C reaches the child.
- The predicate was `err != nil`: EVERY failure counted as a transient
  early-boot race, so an unreachable host spent the full four minutes on
  ~16 attempts that could not succeed. sshRegisterRetryable now retries
  the races it was written for (Permission denied before cloud-init
  writes authorized_keys; curl exit 6/7/28 from an instance whose
  resolver is not up) and stops on reachability failures. An
  UNRECOGNISED message stays retryable, so a wording we have not seen
  degrades to the old behaviour rather than giving up early.

Gates confirmed to fail on revert: returning nil from the timeout, and
restoring `err != nil` as the predicate.

The first version of the timeout test PASSED against the broken code,
because it probed 127.0.0.1 and this machine runs sshd — waitForSSHReady
hardcodes port 22, so "unreachable" has to be unreachable for the
probe's port, not for one I picked. It now uses 203.0.113.1 (TEST-NET-3).
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.92308% with 41 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_single.go 0.00% 31 Missing ⚠️
cmd/launch_posthook.go 70.58% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit cc32903 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/740-ssh-readiness-gate branch October 8, 2026 03:22
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