proxy/server: finish the RPC when the client half-closes - #628
Open
sfc-gh-pkowalewski wants to merge 1 commit into
Open
proxy/server: finish the RPC when the client half-closes#628sfc-gh-pkowalewski wants to merge 1 commit into
sfc-gh-pkowalewski wants to merge 1 commit into
Conversation
When the request channel closed, dispatch called ClientCloseAll and returned straight away, which left doneChan without a reader. Any target stream that finished after that blocked forever trying to report itself, so its wg.Done never ran, TargetStreamSet.Wait never returned and Proxy never returned. The RPC only ended once the client disconnected, and it therefore reported "Unavailable: transport is closing" nearly every time. Keep reading doneChan after the client half-closes and return once the stream set has drained. Nothing changes while the client is still sending. On our staging proxy this took the share of proxy RPCs recorded as failed from 97.9% to zero, measured over several thousand calls.
sfc-gh-pkowalewski
force-pushed
the
pkowalewski/proxy-dispatch-donechan-deadlock
branch
from
August 8, 2026 09:19
b845289 to
b38a236
Compare
sfc-gh-pkowalewski
marked this pull request as ready for review
August 8, 2026 09:24
sfc-gh-ikryvanos
approved these changes
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is wrong
When the request channel closes,
dispatchcallsClientCloseAlland returns straight away, which leavesdoneChanwithout a reader. Any target stream that finishes after that point blocks forever trying to report itself, so itswg.Donenever runs,TargetStreamSet.Waitnever returns andProxynever returns.The RPC therefore only ends when the client disconnects, and the status it reports is whatever the dead transport gives back. In practice that means almost every proxied call finishes as
Unavailable: transport is closing, even though the call itself succeeded. Anything reading that status is misled: on our staging proxy 97.9% of proxy spans were recorded as errors, against roughly 3% real failures in the gRPC metrics.The change
Keep reading
doneChanafter the client half-closes, and return once the stream set has drained.TargetStreamSet.Emptyis new and reports whether any stream is still expected to report completion.Nothing changes while the client is still sending. Streams are only ever added in
Addand removed inRemove, andRemoveis called from thedoneChanhandler alone, so an empty set means every goroutine has finished andWaitreturns immediately.Testing
proxy/proxy/rpcstatus_test.goasserts the status gRPC reports for the proxy RPC, which is the value tracing exporters turn into a span status. It covers a single target, several targets, and a server-streaming method. All three fail on the current code withUnavailable: transport is closingand pass with this change.go test ./proxy/... -race -count=2passes. One unrelated pre-existing failure in./server(TestServerWithUnixCredentials, supplementary group subtests) also fails on an unmodified checkout on macOS.Deployed on our staging proxy, this moved proxy RPCs recorded as failed from 97.9% to zero over several thousand calls.