Repository navigation
fix(relay): a failed Exec must not return a gRPC OK status (#295) - #309
Conversation
) The worker reports a failed Exec as an in-stream ExecEvent.error and then stops. routeExec yields that event and returns NORMALLY (relay.ts sets done on ev.error), so the exec handler's `for await` fell out and reached call.end() -- a gRPC OK. Its catch only ever fired for a *thrown* error, never an in-stream one. A client that reads the terminal status therefore counted a FAILED Exec as a success: it entered `throughput`, entered the distribution `p95` is taken over, and never reached `execErrorsByCause`. That inflates exactly the throughput figures the E11 work is trying to move, which is why the recent runs had to use SH_E11_EXEC_CLIENT=go. Terminate the stream with INTERNAL instead, carrying the worker's message as the status details. INTERNAL rather than grpc-js's default UNKNOWN for a bare Error: ExecEvent.error means the exec machinery failed server-side, whereas a command that merely exited non-zero arrives as ExecEvent.end{exitCode}. The error event is still written before the status, so clients that read the in-stream error are unaffected -- both do (grpc-relay-transport.ts rejects on ev.error, and the Go exec-driver tracks it as a failure), and the TS transport's finish() is idempotent, so the added stream error is dropped as a late frame rather than double-settling. A client cancel also arrives as an ExecEvent.error -- the worker acknowledging our own abort -- and is not a server-side failure, so it is excluded and still drains cleanly. The pre-existing cancellation test passes unchanged, which is what pins that distinction. Presence of the error is tracked as a flag, not by testing the message text: an ExecEvent.error with an EMPTY message is still a failing Exec, and classifying on the text alone would silently re-admit it as a success (the Go exec-driver's sawErr note records the same lesson). Not included: e11-density.sh's exec_error_note_for() now describes a defect that no longer exists on the grpcurl path. Re-wording it means asserting how that path records status after this change, which wants a metal run to confirm, and the file is contended by the rossoctl#302/#306/rossoctl#305 work. Left for a follow-up. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
mrsabath
left a comment
There was a problem hiding this comment.
Tightly scoped fix for a real and well-diagnosed defect. One nit inline, no must-fix.
I verified the central claims rather than taking them from the description:
- The root cause is exactly as described.
relay.ts:125isif (ev.end || ev.error) done = true, androuteExec's loop doesif (ev.end || ev.error) return— so the generator returns normally after an error event, thefor awaitfalls out, and the oldcall.end()reported OK. The pre-existingcatchgenuinely could not fire, since nothing throws. call.destroy(err)is the established pattern in this handler, not a new mechanism: the missing-exec-field guard (main.ts:76) and thecatchblock (main.ts:113) both already use it. The earlyreturnstill runsfinally, so thecancelledlistener is removed on every path.- The cancel exclusion is genuinely pinned by the pre-existing test. That test emits
cancelled, then feeds{error: {reqId: 1, message: 'aborted'}}, and asserts bothcall.ended === trueandcall.destroyed === undefined. Without the!cancelledguard it would fail — so "passes unchanged" is a meaningful claim here, not a vacuous one. - No race can bypass the guard in the cancel direction. The worker only emits the acknowledging error frame in response to the
abortframe thatrouteAbortwrites from insideonCancelled, socancelled = trueis always set first. The reverse ordering (real failure, then client cancel) does suppress theINTERNALstatus, but the client has already cancelled and will not read the terminal status, so nothing is lost. - The flag-not-text decision is right and the reasoning generalises:
ev.error.message ?? ''means an error event with an empty message still setssawExecError, so it cannot be silently re-admitted as a success. INTERNALoverUNKNOWNis the correct call —ExecEvent.erroris a server-side machinery failure, and a non-zero command exit arrives separately asExecEvent.end{exitCode}, so the two are not conflated.- The error event is still written before the status, so in-stream readers are unaffected — consistent with the note about
finish()being idempotent in the TS transport.
The deferred e11-density.sh note is the right call given that file is contended by #302/#306/#305, and flagging it as follow-up rather than leaving it silent is the correct handling.
Areas reviewed: TypeScript (gRPC server handler, error semantics), tests, security (no secrets, no new deps)
Commits: 1, signed off ✓
CI status: all 13 checks passing (CodeQL, Trivy, lint, shellcheck, proto, microvm-gates, check)
Verdict: APPROVE — 1 nit, no must-fix.
| function execStreamError(message: string): Error { | ||
| const err = new Error(message) as Error & { code: number; details: string }; | ||
| err.code = status.INTERNAL; | ||
| err.details = message; |
There was a problem hiding this comment.
nit — err.details is set but never asserted.
This is the field that actually carries the cause to the client, and it is the one part of execStreamError no test touches. The new test asserts .message and .code; the PR body reports proving the code assertion has teeth by temporarily stripping err.code (expected undefined to be 13), but details got no equivalent treatment.
It matters slightly more than a typical unasserted field because message and details are set from the same variable here, so a test reading .message passes whether or not details survives. Delete this line and the suite stays green — yet a client reading e.details (the conventional grpc-js accessor for status details) would get undefined. One more assertion closes it:
expect((call.destroyed as { details?: string } | undefined)?.details).toBe('exec failed: boom');Not blocking: grpc-js populates the wire status from code/message on a destroyed call regardless, so the cause does reach the client today.
…ream Follow-up on this branch's own fix. `call.destroy(err)` does not send a gRPC status, so the exec handler replaced rossoctl#295's wrong-OK with something worse: no terminal status at all. On @grpc/grpc-js 1.14.4 a ServerWritableStream sends its status from `_final` (which calls `call.sendStatus`), and Node's Writable never reaches `_final` once `destroyed` is set -- `end()` short-circuits with ERR_STREAM_DESTROYED. Verified against a real bound server and a real client: with `destroy` the client sat 12s with no status, no `end`, no `close` and no `error`; with `emit('error')` it got INTERNAL (13) carrying the worker's message as details. Same result whether or not an event had already been written. A hang is strictly worse than the wrong-OK it replaced, because an OK at least lets a caller finish its rung. The unit test could not catch this: its fake call object records `destroy(err)` and models none of grpc-js's semantics, so it reported success for a handler that in production answers nothing. The status is produced by the transport, not by the handler, so it is now pinned over a real transport. - Route every non-OK termination through `failExecStream`, which emits 'error' -- the listener grpc-js registers in the stream's constructor is what converts the error and ends the stream, and so the only thing that puts a code on the wire. - Fix the two PRE-EXISTING `destroy` paths too, which hang today. One is an ordinary production state: `routeExec` throws `no live worker for sandbox` when the worker died or has not attached yet, and that reached the handler's catch. A malformed request with no exec field now reports INVALID_ARGUMENT, as it is the caller's fault; codes for arbitrary internal throws are left to grpc-js rather than classified here, which is a relay-semantics decision of its own. - New `main-exec-status.transport.test.ts` binds a real server and drives a real client over all three paths. It fails on the destroyed-stream code by timing out, not by reading a wrong code, which is the symptom being fixed. - `fakeExecCall` now registers the 'error' listener grpc-js's own constructor registers, and keeps `destroy` only so a regression back to it stays visible. Verified: sandbox-relay 22 passed / 5 files exit 0; k8s-sandbox 152 passed, 11 skipped, exit 0 (its client settles on the in-stream error first and `finish` is idempotent, so the added status error is dropped as a late frame); make typecheck exit 0; make lint exit 0. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Review: blocking defect found, fixed on the branch (9e67162)The fix as originally written did not work — and failed in a worse way than the bug it On _final(callback) { callback(null); this.call.sendStatus({...this.pendingStatus, ...}); }and a non-OK this.on('error', err => { this.pendingStatus = serverErrorToStatus(err); this.end(); });Node's Measured against a real server and a real client
Identical with and without a prior Why the test passed anyway
What changed
Verification
RED→GREEN on the new test: 3 failed by 8s timeout before, 3 passed in 186 ms after. The Still deferred
|
Closes #295.
The defect
main.ts's exec handler ended the stream withcall.end()— a gRPC OK — even when theworker had reported the Exec as failed:
routeExecyields anExecEvent.errorand then returns normally (relay.tssetsdone = trueonev.error), so thefor awaitfalls out and reachescall.end(). Thesurrounding
catchonly ever fired for a thrown error, never an in-stream one.A client that reads the terminal status therefore counted a failed Exec as a success: it
entered
throughput, entered the distributionp95is taken over, and never reachedexecErrorsByCause.e11-density.sh's ownexec_error_note_for()documents this on thegrpcurl path, and it is why the recent throughput runs had to use
SH_E11_EXEC_CLIENT=go.The fix
Terminate with
INTERNAL, carrying the worker's message as the status details.INTERNAL, not grpc-js's defaultUNKNOWNfor a bareError:ExecEvent.errormeans theexec machinery failed server-side. A command that merely exited non-zero is a different thing
and arrives as
ExecEvent.end{exitCode}.are unaffected. Both do:
grpc-relay-transport.ts:166rejects onev.error, and the Goexec-driver tracks it as a failure. The TS transport's
finish()is idempotent, so the addedstream error is dropped as a late frame rather than double-settling.
ExecEvent.error— the workeracknowledging our own abort — which is not a server-side failure. The pre-existing
cancellation test passes unchanged, and that is what pins the distinction.
ExecEvent.errorwithan empty message is still a failing Exec; classifying on the text would silently re-admit it
as a success. The Go exec-driver's
sawErrnote records the same lesson.Verification
sandbox-relaysuitek8s-sandboxsuite (the TS client of this stream)tsc --noEmitmake lintRed-green was verified in both directions: the new test failed with
expected undefined to be an instance of Erroragainst the old handler, and the status-code assertion was separately proven tofail (
expected undefined to be 13) by temporarily strippingerr.code.Plan Step 4's check: no driver depends on the OK-on-error behaviour —
e11-density.shdocuments it as a known defect rather than relying on it.
Deliberately not in this PR
e11-density.sh'sexec_error_note_for()now describes a defect that no longer exists on thegrpcurl path (both branches go stale). Re-wording it means asserting how that path records status
after this change, which wants a metal run to confirm, and the file is contended by the
#302 / rossoctl/moca-experiments#8 / #305 work. Follow-up required — whoever picks up those issues should expect to
touch this note.
🤖 Generated with Claude Code