admin管理员组

文章数量:1287649

How to take into account a timeout so that a request does not hang if a server goes down?

Let's say a client has finished streaming to a server and wants to get a response.

stream.CloseAndRecv()

CloseAndRecv is generated by the protoc-gen-go-grpc utility like this

func (x *Client) CloseAndRecv() (*Response, error) {
    if err := x.ClientStream.CloseSend(); err != nil {
       return nil, err
    }
    m := new(Response)
    if err := x.ClientStream.RecvMsg(m); err != nil {
       return nil, err
    }
    return m, nil
}

I did not find a timeout in the implementation of RecvMsg (but maybe it is there somewhere deep and not obvious) but it seems that this problem is common and should be solved somehow already

本文标签: gogRPC timeout waiting for response from serverStack Overflow