in-solana by Supanode

WebSocket subscription silently stops receiving updates

Your WebSocket subscription stops delivering notifications without a visible error, close event, or disconnection message.

Common causes

  1. Idle timeout. Many RPC providers close WebSocket connections that have been idle for 30–60 seconds with no subscription activity.
  2. Server-side rate limiting. The provider silently drops the connection when you exceed subscription limits.
  3. Network interruption. A brief network issue kills the TCP connection without triggering the close event on the client.
  4. Provider restart. The RPC node restarted or rebalanced connections, dropping existing subscriptions.
  5. Too many subscriptions. Each WebSocket connection has a limit on the number of concurrent subscriptions (typically 10–100 depending on the provider).

How to fix

  1. Send periodic pings. Keep the connection alive with WebSocket ping frames every 20–30 seconds.
const ws = new WebSocket("wss://api.mainnet-beta.solana.com");
const pingInterval = setInterval(() => {
  if (ws.readyState === WebSocket.OPEN) {
    ws.ping();
  }
}, 30_000);
  1. Implement reconnection logic. Always handle the close and error events and re-establish subscriptions automatically.
  2. Monitor for silence. Set a timeout that triggers if no message is received within an expected window. If the timeout fires, assume the connection is dead and reconnect.
  3. Reduce subscription count. Stay within your provider’s limits. Consolidate subscriptions where possible.

How to prevent

  • Use onerror and onclose handlers that automatically reconnect and resubscribe.
  • Track the last message timestamp and reconnect if no data arrives within 2× the expected interval.
  • Consider using gRPC streaming for production workloads — it is more reliable than WebSocket for high-throughput data.

FAQ

Why doesn’t the close event fire? Some network failures (like a NAT timeout or load balancer reset) kill the connection without sending a WebSocket close frame. The client may not detect it for minutes.

What is the maximum number of WebSocket subscriptions? It depends on the provider. The public mainnet endpoint limits to approximately 10 subscriptions per connection. Paid providers typically allow 100–1,000+.

Should I use WebSocket or gRPC for production? gRPC (via Yellowstone) is more reliable and efficient for high-volume streaming. WebSocket is simpler to set up but less robust under load.

Error text variants

  • WebSocket subscription silently stops receiving updates
  • WebSocket disconnects
  • solana websocket stops working
  • subscription not receiving updates

Updated: