From 9e4d95cf6b5e22ef6bb5e713a5a26982a158f3b8 Mon Sep 17 00:00:00 2001 From: ningmingxiao Date: Mon, 9 Sep 2024 11:17:04 +0800 Subject: [PATCH] client:fix ttrpc send hang Signed-off-by: ningmingxiao --- client.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index b1bc7a3fc..dbb3e5988 100644 --- a/client.go +++ b/client.go @@ -535,10 +535,14 @@ 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 - } + var s *stream + ch := make(chan error) + go func() { + s, err = c.createStream(0, p) + if err != nil { + ch <- err + } + }() defer c.deleteStream(s) var msg *streamMessage @@ -547,6 +551,10 @@ func (c *Client) dispatch(ctx context.Context, req *Request, resp *Response) err return ctx.Err() case <-c.ctx.Done(): return ErrClosed + case err := <-ch: + if err != nil { + return err + } case <-s.recvClose: // If recv has a pending message, process that first select {