Skip to content

Fix proxy hang when target is unreachable during client-streaming RPCs#618

Draft
sfc-gh-ikryvanos wants to merge 1 commit intomainfrom
ikryvanos/fix-file-cp-stall
Draft

Fix proxy hang when target is unreachable during client-streaming RPCs#618
sfc-gh-ikryvanos wants to merge 1 commit intomainfrom
ikryvanos/fix-file-cp-stall

Conversation

@sfc-gh-ikryvanos
Copy link
Copy Markdown
Collaborator

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

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
@sfc-gh-ikryvanos sfc-gh-ikryvanos marked this pull request as draft April 10, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant