cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

Heartbeat on SSE connections

Open jerem1e opened this issue 8 months ago • 3 comments

Component(s)

router

Is your feature request related to a problem? Please describe.

When using WunderGraph SSE subscriptions, connections often pass through intermediate gateways, proxies, or load balancers. These components typically have idle timeout configurations that automatically close seemingly inactive connections after a certain period (e.g., 60-120 seconds).

Describe the solution you'd like

Implement a configurable feature within the WunderGraph Gateway/Router to periodically send lightweight SSE comment heartbeats (:\n\n) on active subscription connections. E.g. like this:

subscriptions:
  sse:
    enableHeartbeats: true
    heartbeatInterval: 30s # send a heartbeat every 30 seconds

Describe alternatives you've considered

No response

Additional context

Here is a mozilla guide about SSE where this is mentioned: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format

jerem1e avatar Jun 28 '25 09:06 jerem1e

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.

github-actions[bot] avatar Jun 28 '25 09:06 github-actions[bot]

Hello, you can enable heartbeats but looking at the code, only on accept content-type : "multipart/mixed" and not on "text/event-stream"

Image

https://github.com/wundergraph/graphql-go-tools/blob/master/v2/pkg/engine/resolve/context.go#L37

Image

https://github.com/wundergraph/cosmo/blob/main/router/core/flushwriter.go#L162

also your client needs to be able to handle heartbeats (empty data {} ) https://www.apollographql.com/docs/graphos/routing/operations/subscriptions/multipart-protocol#heartbeats

lghinet avatar Jul 08 '25 06:07 lghinet

Hi @jerem1e, thanks for the issue, this is a great suggestion. We'll take a look at implementing this internally.

endigma avatar Jul 08 '25 09:07 endigma