Skip to content

Close stream when CallServerStream fails before returning - #1099

Open
xgbtxy wants to merge 1 commit into
connectrpc:mainfrom
xgbtxy:fix/call-server-stream-close-on-error
Open

xgbtxy wants to merge 1 commit into
connectrpc:mainfrom
xgbtxy:fix/call-server-stream-close-on-error

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Nov 27, 2026

Copy link
Copy Markdown

Client.CallServerStream opens a ClientStream, sends the single request via stream.Send(req), and closes the send side via stream.CloseSend(). If Send fails with a non-io.EOF error or CloseSend returns an error, CallServerStream previously returned (nil, err) without calling stream.Close().

Because the caller receives a nil ClientStream in these failure paths, it has no handle left to close, which leaks transport-owned stream resources (such as derived cancelable contexts, open response bodies if CloseSend fails after sending, or in-process server goroutines) and leaves client interceptors that wrap ClientStream.Close without an end-of-stream signal.

This change closes the stream before returning an error from CallServerStream, joining any non-nil Close error onto the returned error while keeping io.EOF from Send intact so the caller's Receive still observes the server's error.

Verification

  • Added TestCallServerStreamClosesStreamOnError in connect_test.go covering Send errors, CloseSend errors, joined Close errors, and Send returning io.EOF.
  • Verified go test -race -count=1 ., go test -vet=off -race -short ./..., go vet ./..., and golangci-lint run . pass.

Call stream.Close before returning an error from Client.CallServerStream
when Send fails with a non-io.EOF error or when CloseSend fails, joining
any non-nil Close error onto the returned error. Because CallServerStream
returns a nil ClientStream on error, callers previously had no handle left
to release transport resources or signal stream-wrapping interceptors.

Signed-off-by: Yan Chen <yan8925298@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 02:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

3 participants