router icon indicating copy to clipboard operation
router copied to clipboard

Configure a subgraph websocket ping interval

Open smyrick opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. The graphql-ws protocol supports sending a Ping message. This is useful for detecting failed connections, displaying latency metrics or other types of network probing.

If I have opened a passthrough mode subscription to my subgraph the connection is all good. But we're facing issues with longer intervals between messages. Apollo Router logs a TCP connection reset when no messages have been sent beyond our load balancer after a connection idle timeout.

By capturing traffic, we confirmed neither Apollo Router nor the subgraph actively sends pings/heartbeats on the WebSocket session. Both can respond to heartbeats, but both services are just sitting passive and our LB eventually closes the idle connection.

Describe the solution you'd like Add an option to enable sending a Ping message to a subgraph from Router on a set interval. Having this off by default is ok, but we need an option to turn it on for our subgraphs

subscription:
  enabled: true
  mode:
    passthrough:
      all: 
        path: /subscriptions
        protocol: graphql_ws
        ping_interval: 300 # Some option probably in seconds is fine

Describe alternatives you've considered To keep the connection open we can go and update our subgraph code to also send Ping message because this is bi-directional but we may have to do that across many subgraphs and unfortunately some libraries like DGS don't have support to configure a ping interval either

Additional context This is not a concern if we use the HTTP callback protocol instead

smyrick avatar Feb 08 '24 23:02 smyrick

The implementation of ping message should be implemented in that file and maybe especially there, where you could create an interval stream or so to directly send ping message every X seconds configured. I think it would be enough. But yes we should try to keep the original behavior and set a new option to send ping messages

bnjjj avatar Mar 06 '24 10:03 bnjjj