How to resolve potential grpc::ClientBidiReactor data racing

69 views
Skip to first unread message

Zhanhui Li

unread,
Mar 18, 2024, 10:52:40 PM3/18/24
to grpc.io
Hi gRPC C/C++ community,

I am building C/C++ client for an opensource project using gRPC and we have a bidirectional stream API.

For the client side implementation, we need to create a class, inherting from ClientBidiRecator, overriding some methods.

Note the OnXXDone methods has parameter "bool ok",  requiring "If false, no new read/write operation will succeed, and any further Start* should not be called."

The problem is,  Start{Read, Write} call could be concurrent with the OnXxxDone one.
What would the consequences be if Start* called after On*Done with ok being false? Is there a way to walkaround this?

Best Regards!

Zhanhui Li 

AJ Heller

unread,
Mar 26, 2024, 4:54:09 PM3/26/24
to grpc.io
Hi Zhanhui,

Just in case, please read through the callback API spec to refamiliarize yourself: https://github.com/grpc/proposal/blob/master/L67-cpp-callback-api.md

Note that you can only have one outstanding read or write at a time. If you are calling StartWrite while a previous write's OnWriteDone method has not yet been called, that's improper use of the API (and effectively undefined behavior).

I hope this helps!

Best,
-aj
Reply all
Reply to author
Forward
0 new messages