2
votes

I have created a GRPC server-streaming rpc in Go and client is in Dart.

Normally when running the server locally, if client gets disconnected early while the server is still serving the stream, the context in streaming rpc gets canceled, and server stops serving the stream.

But this isn't same on Cloud Run, when client gets disconnected the server doesn't cancel the context. So, server is never notified that the stream is closed from the client side, unless the container reaches the timeout limit.

Therefore, if timeout is set to 1hour then server is billed for 1hour even when client gets disconnected early.

Does Cloud Run require some special magic or is it not supported currently?

Only workaround currently is to use smaller timeout (~1min) and then create a retry logic on client side.

1

1 Answers

3
votes

As you said, Cloud Run (fully managed) currently only supports server-side streaming. Bi-directional streaming is planned for future, and here's how it's relevant:

Having only "server-side streaming" basically means when the "client" disconnects, "server" will not know about it and will carry on with the request. This happens because "server" is not connected directly to the "client" and the request from the "client" is buffered (in its entirety) and then sent to the "server".

Therefore, in a gRPC server-streaming mode, "client" disconnects/cancellations currently will not be received by your "server" application running on Cloud Run.

Again, if/when bi-directional streaming becomes available on Cloud Run, (even though your RPC is not bi-directional), the "server" will be able to receive the "client" disconnects and therefore cancel request as quickly as possible (instead of completing the request only for it to be discarded by the intermediate proxies).