5

We can't get SSE to send from containers on Google Cloud Run. I've tried hosting a container with just a simple SSE example (https://github.com/kljensen/node-sse-example) to see if it was something in our library -- nope.

I see from the server that clients connect (like the initial GET works), but no events get sent from the server. The EventSource on the client never changes from CONNECTING to CONNECTED.

From the Cloud Run docs, it's a little ambiguous if this would be supported (emphasis mine):

Cloud Run (fully managed) currently does not support HTTP streaming. Therefore, inbound requests with protocols like WebSockets and gRPC (streaming RPCs) are not supported.

As an exception, Cloud Run (fully managed) services support unary gRPC for inbound requests.

For outbound requests, both WebSockets and gRPC are supported on Cloud Run (fully managed).

Wouldn't SSE count as outbound requests, or am I misunderstanding?

Community
  • 1
  • 1
andrew
  • 1,173
  • 2
  • 18
  • 28

4 Answers4

12

UPDATE (October 8, 2020): Server streaming is now supported https://cloud.google.com/blog/products/serverless/cloud-run-now-supports-http-grpc-server-streaming

Not currently. However, this feature (gRPC server-side-streaming and SSE) will be launched very soon. We're working on it actively, stay tuned.

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
  • 1
    So you mean once the feature is delivered, we will be able to keep connections for free, and only pay when data is sent from server to client ? – Denis TRUFFAUT Jun 18 '20 at 10:12
  • 1
    Unlikely. As long as the HTTP request is open, that will be charged. – ahmet alp balkan Jun 18 '20 at 15:42
  • 2
    @AhmetB-Google this is awesome to hear! We are pumped to have this feature. Just curious - does this also mean the maximum request timeout will increase from 900 seconds? – Mike Jun 24 '20 at 14:33
  • @AhmetB-Google any update on SSE support, or is there somewhere we can look to keep up to speed on this going forward? – geg Sep 26 '20 at 04:19
  • SSE is coming soon. Make sure to follow GCP Blog Serverless section. – ahmet alp balkan Sep 26 '20 at 20:51
  • This is now supported https://cloud.google.com/blog/products/serverless/cloud-run-now-supports-http-grpc-server-streaming – Adam LaCombe Oct 08 '20 at 10:19
1

If I refer to the Cloud Run design, the container processing is performed only when a request is handled, the rest of the time, the CPU is close to idle. That's why you are billed only when a request is processed.

If I take the SSE flow, the server initiate a connection to the client. You need processing time (and resources) for establishing and maintaining this connexion. And because it's out of any request, your CPU is idle and it can't work for performing this.

So, I don't have a clear answer to your implementation problem, but, by design, I'm quite sure that Cloud Run can't work with SSE. At least, for now.

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
1

Actually, by outbound requests, they mean the requests made by your container on Cloud Run to some other service. As mentioned by Guillaume, it's currently not possible to stream responses and I guess it's also related to the fact that Cloud Run will buffer every response.

I am myself looking for a workaround and will keep you posted if I find any decent solution

Younes
  • 199
  • 5
1

Well, the current temporary workaround is switching to Google App Engine Flexible and disable response buffering with X-Accel-Buffering: no response header.

Younes
  • 199
  • 5