grpc / grpc.github.io

The grpc.io website. (on GitHub pages)
277 stars 382 forks source link

Fix go client bidirectional example #834

Closed thegrumpylion closed 5 years ago

thegrumpylion commented 5 years ago

In the example of handling bidirectional streaming in the client side, stream.CloseSend() was called before <-waitc which makes no sense. It should be the other way around

thelinuxfoundation commented 5 years ago

Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement.

After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.

Regards, CLA GitHub bot

dfawley commented 5 years ago

stream.CloseSend() lets the server know that the client is done sending messages. waitc is closed when the server successfully terminates the stream (the client detects this by getting io.EOF from Recv()). It's normal for servers to wait until the client does a CloseSend() before ending the RPC.

If you check out the sample server code in our repo here, you will notice that this is exactly what our server does. If we were to reverse the lines as proposed, the client would never indicate it was done sending messages, the server would wait forever, and the RPC and the client would never terminate (until the deadline is reached).