Fix proxy hang when target is unreachable during client-streaming RPCs#618
Draft
sfc-gh-ikryvanos wants to merge 1 commit intomainfrom
Draft
Fix proxy hang when target is unreachable during client-streaming RPCs#618sfc-gh-ikryvanos wants to merge 1 commit intomainfrom
sfc-gh-ikryvanos wants to merge 1 commit intomainfrom
Conversation
TargetStream.Send selected on the gRPC stream context to detect cancellation, but before the stream is established (during dial/NewStream), that context belongs to the placeholder unconnectedClientStream and never gets cancelled on connection failure. This caused Send to block forever when reqChan was full and the target was unreachable. Two changes fix this: 1. Send now selects on s.ctx (the TargetStream's own context) instead of the gRPC stream context. s.ctx is derived from the caller's context and is cancelled when the parent context is cancelled or when Run() fails. 2. Run() now calls s.cancelFunc() when NewStream fails. Previously only DialContext failure cancelled the stream context; a NewStream failure left in-flight Send() calls blocked indefinitely. Together these ensure that when a target is unreachable, the proxy propagates the error back to the client instead of hanging. Made-with: Cursor
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.
TargetStream.Send selected on the gRPC stream context to detect cancellation, but before the stream is established (during dial/NewStream), that context belongs to the placeholder unconnectedClientStream and never gets cancelled on connection failure. This caused Send to block forever when reqChan was full and the target was unreachable.
Two changes fix this:
Send now selects on s.ctx (the TargetStream's own context) instead of the gRPC stream context. s.ctx is derived from the caller's context and is cancelled when the parent context is cancelled or when Run() fails.
Run() now calls s.cancelFunc() when NewStream fails. Previously only DialContext failure cancelled the stream context; a NewStream failure left in-flight Send() calls blocked indefinitely.
Together these ensure that when a target is unreachable, the proxy propagates the error back to the client instead of hanging.
Made-with: Cursor