Repository navigation
feat(fabric-api): Bound Looking Glass delivery and stop stalled streams - #1116
Conversation
A Looking Glass consumer that stopped reading could hold a request's execution indefinitely. Each event went to stream.Send from the handler goroutine, and gRPC flow control blocks that call until the client reads, so the handler never returned, finished router outcomes waited for it without a bound, and the request's live stream and queue reservation stayed held. A follower relaying for the leader had the same unbounded Send. Nothing capped a stream's output, the gateway listener had no keepalive, no per-replica call or connection cap and a window that grows with bandwidth-delay estimation, and a shutdown signal left service streams running until the manager exited. Every stream now has one writer goroutine. The handler waits at most 2 s for each write and a finished outcome waits at most 2 s for the stream's two-outcome buffer; past either, the request is cancelled and the handler returns CANCELLED. Returning resets the stream, which ends the blocked Send, so the write is aborted at the transport rather than only timed at the producer. A follower relays one event at a time through the same writer and never forwards a call twice. An outcome over 144 KiB is delivered as a ResponseTooLarge failure. The stream keeps 64 KiB for its complete event and 1 KiB for each router still to report; once an outcome does not fit the 5 MiB budget, that router and every router still running fail with the new OutputLimitExceeded code, which also becomes the terminal reason, so every selected router still has exactly one outcome. Each replica refuses RunDiagnostic calls beyond 32 and forwarded calls beyond 16 with QueueFull and a 1 s retry delay, and closes a service identity's connection beyond 64 after its handshake. The listener and a follower's connection to the leader use fixed 64 KiB windows and buffers. Server keepalive pings a silent peer after 4 s and closes it 4 s later, so a blackholed client's work is cancelled within 10 s. A shutdown signal stops the gRPC server at once, cancelling service and operator calls in flight. Tests measure each bound against the contract: a stalled consumer on the leader and through a follower releases its routers, queue, reservation and stream about 2 s after its write blocks; a slow hand-off cancels the request; cancellation during discovery, while queued and while executing releases everything within 2 s; stopping the server and a blackholed connection cancel running routers; 16 streams of maximum-size outcomes stay within 5 MiB each and a bounded number of goroutines; a lost forwarded stream is not forwarded again and runs no router twice; a gateway replaced as lease holder dispatches nothing new; and the call and connection caps refuse and free slots. The stalled-consumer test hangs without this change. Service disable remains a startup setting; its runtime control, metrics and packaged configuration are left to #1047. Fixes #1046
|
Two independent reviews ran on dabb247. The adversarial review returned merge after reading the writer, cancellation and transport changes and running the fabric unit tests under the race detector. The conventions review returned merge after checking the title, body, commit, draft state and overlap with other open PRs. The adversarial review could not run lint, build or the end-to-end suite itself. CI has since passed all of them on this head, after a rerun of two jobs that timed out while downloading LLVM packages. Auto-merge is off on purpose. This PR targets the branch of #1115, so it should merge by hand once #1115 has merged and this PR has retargeted to main. |
ecv
left a comment
There was a problem hiding this comment.
Approve.
Bounds a stalled Looking Glass consumer on both the leader and the forwarding follower, and every cut-off surfaces as an explicit status rather than a silent drop. It merges cleanly onto main now that #1115 is in (MERGEABLE, no file conflicts).
- No silent loss for a healthy client: an exhausted stream budget turns the router's result into an
OutputLimitExceededfailure outcome (fitinservice.go), withfailureReserveandmaxCompleteByteskept back so the terminalcompleteevent still fits. An oversized result becomesResponseTooLarge. A stalled consumer gets aCancelledstatus ("did not read within the write bound") and nocomplete, which is loud. - Overlap with #1115: it merged as a179ca1 and touches the permit and node files plus some of the same gateway files (
service.go,runner.go,debug.go,errcode.go, docs). This PR's own 11 files are a clean delta on current main. gateway.gonow stops the gRPC server the moment the shutdown context ends, which also cuts operator debug calls in flight (the description says so). Acceptable on shutdown.transportOptionsapplies to the whole gateway listener, so the 64 KiB windows andkeepaliveMinTime5s also bind operator and forwarding clients. In-repo clients are fine (the leader dial sets 10s); an external operator client pinging faster than 5s would get GOAWAY.
Follow-ups:
- The 2s hand-off timer (
SendBound) starts per finished-router callback, and callbacks run concurrently with anoutcomeBufferof 2. With many routers finishing together and a reader that takes about 1s per write, later callbacks queue behind siblings and can triperrConsumerStalledfor a slow but live client. Consider timing consumer progress rather than queue wait, or sizing the buffer to the router cap. - A 144 KiB result through a fixed 64 KiB window needs a few round trips inside the 2s write bound; a client on a slow or high-latency link could be cut. Worth a note in the service contract on minimum client throughput.
Summary
A Looking Glass client that stops reading can hold its request's routers, queue slots and stream slot forever, since nothing bounds a write to it or the output it receives.
Each stream now has one writer, and a write or a finished router result waiting more than 2 seconds cancels the request, on the leader and through a forwarding replica. Streams are capped at 5 MiB and router results at 144 KiB, and each gateway replica caps concurrent calls and service connections, fixes its flow-control windows, closes silent connections within 10 seconds and stops serving at once on shutdown.
The customer service stays disabled, but shutdown now also cuts off operator calls in flight, and a runtime off switch is left to #1047.
Test plan
Stacked on #1115, which must merge first.
Fixes #1046