Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client:fix ttrpc send hang #173

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,26 +535,34 @@ func (c *Client) dispatch(ctx context.Context, req *Request, resp *Response) err
return err
}

s, err := c.createStream(0, p)
if err != nil {
return err
}
defer c.deleteStream(s)
var s *stream
ch := make(chan error)
go func() {
s, err = c.createStream(0, p)
ch <- err
}()

var msg *streamMessage
select {
case <-ctx.Done():
return ctx.Err()
case <-c.ctx.Done():
return ErrClosed
case <-s.recvClose:
// If recv has a pending message, process that first
case err := <-ch:
defer c.deleteStream(s)
if err != nil {
return err
}
select {
case <-s.recvClose:
// If recv has a pending message, process that first
select {
case msg = <-s.recv:
default:
return s.recvErr
}
case msg = <-s.recv:
default:
return s.recvErr
}
case msg = <-s.recv:
}

if msg.header.Type == messageTypeResponse {
Expand Down
Loading