Why your Solana WebSocket stops receiving messages, and how to keep it alive

Your bot ran fine for two hours and then stopped seeing anything. No error, no close event, the socket still says it is open. This is the most common failure with Solana WebSockets, and reconnecting on close does not fix it.

What is happening

A WebSocket can die without telling you. A provider restarts a node, a load balancer drops an idle connection, or the subscription is discarded on the server while the TCP connection stays up. Your onclose never fires. From your side the feed just goes quiet.

The fix is to watch for silence

  1. Set a silence timer. Every message resets it. If nothing arrives for, say, 30 seconds, treat the socket as dead: close it and open a new one.
  2. Give the handshake a deadline. A connection that never opens also fires no event on some networks.
  3. Back off with jitter. Wait 0.5 s, 1 s, 2 s, up to 30 s between attempts, randomised, so a fleet of clients cut off together does not return together.
  4. Resubscribe everything. Subscriptions belong to the connection. A new socket has none, and the subscription ids change.

The quiet-subscription problem

Silence only means something if messages are expected. An accountSubscribe on a wallet that trades once an hour is silent for an hour while perfectly healthy. Two options:

What you still lose

Whatever happened while the socket was down is not replayed. If you need every transaction, backfill after reconnecting: call getSignaturesForAddress over HTTP for the gap.

Working code

solana-ws-keepalive does the silence timer, handshake deadline, backoff, resubscribe and heartbeat, with no dependencies:

import { createStream } from "solana-ws-keepalive";

const stream = createStream({
  url: "wss://your-rpc.example/?api-key=...",
  silentMs: 30_000,
  heartbeat: true,
  onState: (state, info) => console.log(state, info.why ?? ""),
});

stream.subscribe("logsSubscribe",
  [{ mentions: ["<program or wallet>"] }, { commitment: "confirmed" }],
  (result) => console.log(result.value.signature));
npx github:blixvip/solana-ws-keepalive logs <address>

Several subscriptions share one socket and all come back after a reconnect. Node 22 or newer has WebSocket built in; on older versions pass the ws package.

Want it done for you?

This is the small, open version. Blix is the AI-powered Solana memecoin terminal it comes from: every pump.fun launch live, AI coin ratings, narratives, wallet and X tracking, and one-click trading with 0% fees. There is a public API and an MCP server too.

Start trading on BlixJoin the Discord

Help build it

solana-ws-keepalive is open source and takes pull requests. There are good first issues with step-by-step instructions, and setup is git clone and npm test.

More guides

How to get a pump.fun token's market cap and bonding curve progress without an APIpump-curveHow to detect new pump.fun tokens in real time (and stream every trade)pump-streamHow to calculate a Solana token's top 10 holders percentage (and why explorers overstate it)sol-holdersHow to parse a Solana swap transaction for any DEXsolana-swap-parserHow to stop Solana RPC 429 errors (Too Many Requests)solana-rpc-pool