Repository navigation
fix(egress): a refusal after Unregister's abort writes nothing to the guest - #829
Conversation
… guest proxyConn.abort sets aborted, then cancels the conn's context before it closes the guest conn. A forwarded request whose RoundTrip failed because of that cancel reached refuse, which suppressed its event (emit checks aborted) but still wrote a 502 Bad Gateway to the guest conn not yet closed. The conformance case unregister_aborts_inflight caught it once in CI. refuse, and icConn.refuse on the TLS-intercepting path, now write and emit nothing on an aborted conn: abort's aborted event is the conn's one terminal event, and abort closes it. Closes rossoctl#825 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Clawgenti Code Review
Reviewed against upstream main (verified proxyConn.abort() sets aborted under pc.mu before cancel(), so a request failing because of that cancel always observes it set — the fix's precondition holds on both refuse paths). The change is minimal and correctly scoped: both proxyConn.refuse and icConn.refuse bail out before writing or emitting, keeping abort's event as the conn's single terminal event. Test coverage is good, including the live-conn regression case.
No must-fix findings. One suggestion below.
Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (egress proxy), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: all checks passing
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| // event and closes the conn, and a refusal reached after it is the echo of | ||
| // abort's own cancel (an upstream request that failed because it was | ||
| // cancelled), which the guest must not read as the proxy's answer. | ||
| func (pc *proxyConn) refuse(e Event, host string) { |
There was a problem hiding this comment.
suggestion — There's an inherent TOCTOU window here: abort() can run after wasAborted() returns false, and the old behavior (502 written to a conn abort is about to close) briefly reappears. This is benign in practice — abort() closes pc.c right after, so the writeAndClose either fails on a closed conn or the guest is going away regardless — but it might be worth one sentence in the refuse doc comment saying the check is best-effort and the close in abort is what actually seals the window, so a future reader doesn't try to "fix" the race with a lock held across the write.
Suggested fix: extend the doc comment; no code change needed.
clawgenti
left a comment
There was a problem hiding this comment.
Review complete.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Fixes #825: a request whose upstream RoundTrip failed because abort() cancelled the conn's context reached proxyConn.refuse, which suppressed the event but still wrote a 502 Bad Gateway to the guest before abort closed the conn. refuse and icConn.refuse now return immediately when the new pc.wasAborted() (read under pc.mu) is true.
I checked the ordering against the head: abort() sets aborted = true under pc.mu, releases the lock, then calls pc.cancel() and pc.c.Close(). Any failure caused by that cancel therefore always sees aborted, so the fix closes the reported race. handle() returns false after a refusal and serve returns, so nothing else writes to the guest. Non-aborted conns are unchanged; TestRefuseStillWritesOnALiveConn covers that.
Note (informational, not a blocker): a refusal decided before abort (e.g. policy deny) can still pass the check and then write its 502 while abort runs concurrently. Its event is suppressed by emit and abort's aborted is the terminal event. That is a genuine proxy answer rather than the echo of abort's cancel, so it is acceptable and out of scope for #825.
The tests are sound. They build the exact post-cancel/pre-close state. The intercept test relies on a nil gtls panicking (recovered) to prove no write happens. They use the same //go:build unix tag and recSink helper as proxy_test.go.
Areas reviewed: Go (remote-worker/internal/egress), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: all 17 checks passing (mergeable_state blocked = awaiting required review)
Prompt-injection check: none found in title/body/diff/commit
Takes upstream main at 1a7f41e (19 merges since 032c8f6): the sandbox idle lifetime across docs, control plane, clients and deploy (rossoctl#820, rossoctl#837, rossoctl#842, rossoctl#843), grant redemption (rossoctl#822), the lease-check log line (rossoctl#824), egress fixes (rossoctl#829, rossoctl#834), the mock wait (rossoctl#828), the deadline timer (rossoctl#835), the create rollback (rossoctl#832), multi refusals and the rossoctl#363 leftovers (rossoctl#833, rossoctl#838), the identity near-miss check (rossoctl#827), mocactl login errors (rossoctl#836), the ghostunnel probes (rossoctl#830), refusal-burst deferral (rossoctl#831), a sandbox-worker change (rossoctl#841) and the v0.11 doc truth (rossoctl#821). Conflicts (one): - deploy/sbx/README.md, the "Optional inputs" table. Upstream (rossoctl#843) rewrote the SBX_LIFETIME_DAYS row (the default idle lifetime, at most SBX_MAX_LIFETIME_DAYS) and added the SBX_MAX_LIFETIME_DAYS and SBX_LOWER_WORKSPACE_IDLE rows, which widened the table; the fork had added an SBX_GATE_RECORD_SCHEMA row at its end. Resolved by taking upstream's table whole and appending the fork's SBX_GATE_RECORD_SCHEMA row after SBX_PROFILE, then re-padding the table with prettier. The fork's env-file example line for SBX_GATE_RECORD_SCHEMA merged cleanly. Merged without markers, checked: setup.sh keeps the fork's SBX_GATE_RECORD_SCHEMA validation and its sbx-settings write (so it stays in the settings hash) beside upstream's SH_SANDBOX_MAX_LIFETIME_SECONDS; both ocp-sbx and ocp-combined patch-control-plane.yaml keep the optional SH_GATE_RECORD_SCHEMA from sbx-settings beside the new optional SH_SANDBOX_MAX_LIFETIME_SECONDS; setup.test.sh keeps the fork's cases beside upstream's. The fork's RUNBOOK, README and template-onboarding docs say nothing about sandbox lifetime, refusal bursts, login errors or the create rollback, so none needed a correction; GUIDE.md is unchanged and GUIDE.pdf is not regenerated. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #825
What changed and why
proxyConn.abort()(proxy.go) setsaborted, writes the conn'sabortedevent, then callspc.cancel()beforepc.c.Close(). A forwarded request whosetr.RoundTripfails because of that cancel reachespc.refuse(…)(handler.go).refusesuppressed its event, sinceemitchecksaborted, but it still calledwriteAndClose(pc.c, refusalBytes(…))on the guest conn, which wasn't closed yet. In feat(microvm,sbx): from an image to a registered template; manifest hash v2 and the template record check #771's CI run,unregister_aborts_inflightcaught the guest reading that502 Bad Gateway.refusenow returns at once on an aborted conn: it writes nothing and emits nothing.abort'sabortedevent stays the conn's one terminal event, andabortcloses the conn.icConn.refuse(intercept.go, the TLS-intercepting path's refusals) had the same gap: it emitted throughemitand then wrote over the guest TLS. It gets the same check.pc.wasAborted()underpc.mu.abortsetsabortedbefore it cancels, so any request failure caused by that cancel always sees it set. A refusal on a conn that was not aborted is unchanged.Tests
remote-worker/internal/egress/abort_test.gobuilds aproxyConnin exactly the stateabortleaves between its cancel and its close (aborted, context cancelled, guest conn open):TestRefuseWritesNothingOnAnAbortedConn: the guest reads nothing,refusereturns, and no event is emitted. With the fix reverted, it fails with the CI failure's text:the guest read "HTTP/1.1 502 Bad Gateway\r\nContent-Type: text/plain\r\nX-Moca-Egres" from an aborted conn.TestInterceptRefuseWritesNothingOnAnAbortedConn:icConn.refusedoesn't touch the guest TLS. With the fix reverted, it fails.TestRefuseStillWritesOnALiveConn: a conn that was not aborted still gets its 502 and its one event.go test -race -count=200 -run 'TestConformance/inprocess/unregister_aborts_inflight' ./internal/egress) passes on this branch. On main, 300 runs on this machine did not reproduce the CI failure, so the unit tests carry the proof.remote-worker,go vet ./...andgo test ./...pass, and so doesgo test -race ./internal/egress/.... gofmt is clean, and pre-commit passes.Every commit is signed off (DCO).
Assisted-By: Claude Code