8000 test(minvmd): hold a marker's connection open past its handshake by norrietaylor · Pull Request #1846 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

test(minvmd): hold a marker's connection open past its handshake - #1846

Merged
norrietaylor merged 1 commit into
fix/ci-gvproxy-before-vm-harnessfrom
fix/escape-flake-1845
Oct 3, 2026
Merged

norrietaylor merged 1 commit into
fix/ci-gvproxy-before-vm-harnessfrom
fix/escape-flake-1845

Conversation

@norrietaylor
Copy link
Copy Markdown
Member

Fixes the flake in #1845.

The mechanism

HostListener armed a 2-second read timeout the moment it accepted a connection, and on that timeout dropped the connection without recording anything (got == 0, so nothing was pushed to seen).

The listener's clock does not start where the test assumes. gvisor-tap-vsock's TCP forwarder dials the backend before it creates the endpoint that answers the SYN — pinned v0.8.9, pkg/services/forwarder/tcp.go:34:

outbound, err := net.Dial("tcp", net.JoinHostPort(localAddress.String(), fmt.Sprint(r.ID().LocalPort)))
if err != nil { r.Complete(true); return }
var wq waiter.Queue
ep, tcpErr := r.CreateEndpoint(&wq)      // the SYN-ACK is only sent here

So the order is: spoofer's SYN → gvproxy dials 127.0.0.1:<port> → the listener accepts and arms its 2 s timer → CreateEndpoint → SYN-ACK → spoofer's ACK and PSH. The listener is counting down through the handshake it is supposed to be waiting after.

The spoofer's gratuitous ARP claim buys nothing against that clock: gvisor discards a confirmation for which it holds no entry (neighbor_cache.go, handleConfirmation returns early), so the stack must issue its own ARP request, and defaultRetransmitTimer is a whole second. One SYN-ACK retransmit puts the PSH at ~1 s and it survives; two put it at ~3-4 s and the connection is already gone — while spoofed_flow still returns Ok(()) well inside its own 10 s FLOW_DEADLINE. That is the observed signature exactly: handshake completed, marker never arrived, and 10 s of wait_for spent against a socket that no longer existed.

It is a wall-clock threshold crossing, which is why the same tree failed twice and passed once.

The change

  • Hold an accepted connection for CONNECTION_BUDGET (30 s), longer than the longest wait_for, instead of closing it on the first read timeout. A read timeout is not an end — the sender may still be completing the handshake this connection was dialed for.
  • Record each read as it arrives rather than once at the end, so a marker is readable the moment its bytes are.
  • Read each connection on its own thread, so a sender that is slow to push — or never pushes — delays neither the accept loop nor another sender's marker. The spoofed flows never send a FIN, so under the old loop each one occupied the accept loop for its full timeout.
  • Report what the listener saw when the wait fails. Today a failure prints nothing about the listener, so this class is undiagnosable from a CI log; the message now distinguishes a connection never dialed, one dialed and silent, and one that arrived after the wait gave up.

No production code changes.

Deliberately not done

  • No PSH retransmission. The spoofer writes the push once and never resends, so any genuinely lost segment is still terminal. Adding a resend means plumbing the listener into spoofed_flow; worth doing only if the failure survives this.
  • No change to the gate. relay_frames' tokio::select! (crates/minvmd/src/net/egress_gate.rs:1199) has no biased;, so when the ingress leg wins the race the pinned egress future is dropped un-drained and any frame still buffered from the guest is discarded — and table.report_withdrawals at :2235 never runs, so the box's row outlives its shuttle connection. That is a real defect, and near-unreachable in production where a shuttle is not closed right after a data frame. It is out of scope here and should get its own issue rather than be bundled into a test fix.

Base

Stacked on fix/ci-gvproxy-before-vm-harness (#1 8000 815), because the test region only exists there — the file is 1358 lines on main and 1628 with that change. Retarget to main once #1815 lands.

Verification

cargo fmt, cargo check and cargo clippy on -p minvmd --test vm_escape_integration are clean. The test itself needs /dev/kvm, so the CI lane is the only place it runs; a flake at roughly two in three gives usable signal within a few runs.

The host listener armed a 2s read timeout the moment it accepted a
connection, and discarded the connection unrecorded when that timeout
fired. gvisor-tap-vsock's TCP forwarder dials the backend *before* it
creates the endpoint that answers the SYN, so the listener accepts,
and starts that clock, before the sender has seen the SYN-ACK it must
answer before it can push. A handshake slower than ~2s — one SYN-ACK
retransmit on a loaded runner is enough — left the marker nowhere to
land: the flow completed, and the wait meant to grant it 10s spent
them against a socket already closed.

Hold each connection for a budget longer than the longest wait, record
every read as it arrives rather than once at the end, and read each
connection on its own thread so one silent sender cannot delay another
sender's marker. Report what the listener saw when a wait fails, so a
next occurrence says whether the connection was never dialed, was
dialed and stayed silent, or arrived after the wait gave up.

Refs: #1845
@norrietaylor
norrietaylor requested a review from a team as a code owner October 3, 2026 03:06
@coderabbitai
coderabbitai Bot commented Oct 3, 2026
Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 53b78755-ae7a-4304-a204-12eb5d4aff63

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@minimal-foundry
minimal-foundry Bot commented Oct 3, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at a6d5653d1677.

Nothing to do.

Clobber: none: git log on the file shows the prior commit (40d9b75) touched the minvmd helper/teardown, not this listener, and this diff neither reverts nor overlaps it.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — approved

Verdict APPROVE — No findings.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 3, 2026
@norrietaylor
norrietaylor merged commit 2587047 into fix/ci-gvproxy-before-vm-harness Oct 3, 2026
3 checks passed
@norrietaylor
norrietaylor deleted the fix/escape-flake-1845 branch October 3, 2026 03:18
yermakoffivan pushed a commit to yermakoffivan/minimal that referenced this pull request Oct 3, 2026
…ominimal#1815)

* ci: fetch the gvproxy switch before the VM harness step and export it

Both VM lanes fetched the pinned gvproxy switch only after the "VM integration
harnesses" step and never exported MINVMD_GVPROXY_BIN to it, so every harness
that needs the host switch skipped and counted as a pass. Fetch it once ahead of
the harness step, drop the later duplicate, and give the harness step
MINVMD_GVPROXY_BIN plus the MINVMD_VM_LANE marker.

* revert(ci): leave the frozen workflows untouched

* test(minvmd): fetch the pinned gvproxy switch for VM harnesses under MINVMD_E2E

* test(minvmd): give the vm_escape boxes a package source and the switch

The vm_escape harness never ran a box: a shell exec launches the box's
sandbox, which resolves the baseline packages against the project's package
graph, and the harness uploaded a minimal.toml with no [upstream], so every
exec failed with "no such package: base". It also booted with
`minvmd boot --foreground`, which never stands up the gvproxy switch, so the
guest daemon could not have fetched packages anyway.

- Carry the pinned [upstream] (gominimal/pkgs at f4de33d0) in the boxes'
  minimal.toml, shared as common::PKGS_UPSTREAM. The guest daemon fetches it
  as node-plane traffic; under MINVMD_E2E=1 a failed fetch fails the test.
- Boot through the supervisor path (`minvmd run --detach`, poll
  `status --json` until Running, `minvmd stop` on drop), with
  MINVMD_VM_OWN_IP and the helper's MINVMD_GVPROXY_BIN, and read the gate's
  lines from the detached supervisor's JSON log.
- Gate a Pending ConfigureLoadout the way the CLI's no-prompt hook answers
  vars, failing on any patch or hook, and submit the verdict.
- Return each exec's stderr and quote it when an exec exits nonzero, so a
  box that cannot launch names its cause.

* fix(minvmd): reap the VMM child when a boot harness tears down

boot_integration and minimald_session_integration SIGKILLed
`minvmd boot --foreground` alone. Its `__krun-vmm` child was reparented to
init and kept the VM running, holding the harness's inherited stdio open,
which nextest reported as LEAK and which piled up on persistent runners.

Spawn the boot as its own process group with stdin off the terminal, and
tear down with common::kill_group, which kills the whole group before
reaping the parent.

* fix(minvmd): kill the boot harness's process group with killpg

procps `kill -KILL -<pgid>` exits 0 on Linux without signalling the group,
so the reap that followed blocked on a still-running `minvmd boot` and the
KVM lane timed out in boot_integration. Signal the group with killpg(2) and
kill the parent directly as well, so the reap cannot block on a group
signal that missed.

* fix(minvmd): harden vm_escape's minvmd helper and teardown

- Export MINVMD_READY_TIMEOUT_SECS (150 s) to the supervisor: `--timeout`
  bounds only `run --detach`'s poll, and the READY wait otherwise defaults
  to 60 s, short of a cold boot on a lane that does not set it.
- Drain the subcommand's stdout and stderr on reader threads while it runs,
  so a child that writes more than a pipe buffer cannot stall into the
  timeout. The Output shape and the timeout are unchanged.
- Guest::drop never panics: `minvmd stop` runs through a non-panicking
  bounded helper, and when it errors or times out the VMM pid recorded from
  `status --json` is killed and the failure logged.

* test(minvmd): hold a marker's connection open past its handshake (gominimal#1846)

The host listener armed a 2s read timeout the moment it accepted a
connection, and discarded the connection unrecorded when that timeout
fired. gvisor-tap-vsock's TCP forwarder dials the backend *before* it
creates the endpoint that answers the SYN, so the listener accepts,
and starts that clock, before the sender has seen the SYN-ACK it must
answer before it can push. A handshake slower than ~2s — one SYN-ACK
retransmit on a loaded runner is enough — left the marker nowhere to
land: the flow completed, and the wait meant to grant it 10s spent
them against a socket already closed.

Hold each connection for a budget longer than the longest wait, record
every read as it arrives rather than once at the end, and read each
connection on its own thread so one silent sender cannot delay another
sender's marker. Report what the listener saw when a wait fails, so a
next occurrence says whether the connection was never dialed, was
dialed and stayed silent, or arrived after the wait gave up.

Refs: gominimal#1845

* test(minvmd): print the gate's own account when a marker is lost (gominimal#1849)

The listener's report now shows the spoofed flow's connection being
accepted and then reading nothing, so the loss is after the handshake
and not in the listener's timing budget. What it cannot show is which
side lost the payload.

Print the gate's lines for the flow alongside it. An
egress-unregistered-source line and nothing else means the gate
admitted the frames and the loss is past it, in gvproxy; an
ingress-leg line means the relay came off on the switch side and
whatever the guest had buffered went with it.

Refs: gominimal#1845, #1847

* test(minvmd): hold a spoofed flow open until its marker is acknowledged (gominimal#1864)

* test(minvmd): hold a spoofed flow open until its marker is acknowledged

spoofed_flow wrote the ACK and the marker's push, returned, and dropped
the gate socket: no wait for the switch's acknowledgement and no
retransmit. A frame lost in the relay's or the switch's teardown of that
connection lost the marker with nothing to say where (gominimal#1845).

The flow now resends the push every 500 ms until the switch acknowledges
every marker byte (SPOOF_ISN + 1 + marker length, compared in wrapping
sequence space), answering ARP for its address meanwhile, and reports
whether it was acknowledged. An acknowledged marker that never reaches
the listener was lost past the switch's stack; an unacknowledged one was
lost before it.

* test(minvmd): record whether the switch acknowledged each admitted marker

The admit verdict in the attempts record now carries the marker's
acknowledgement, so a later red run shows whether the ACK path worked
without a pre-fix timing baseline to infer it from.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0