WebSocket disconnecting every ~30s, causing 1-minute delay in real-time updates
reyallisonn-eng
FREEOP

17 days ago

Hi everyone,

I have a Node.js/Express app on Railway using native WebSocket (ws library) for real-time updates in a messaging CRM. My users' WebSocket connections keep dropping and reconnecting very frequently — I've seen connections in the browser Network tab that last only ~30 seconds before closing.

This causes real-time events (new messages, status updates) to take up to 1 minute to show up in the browser, because the client has to reconnect (exponential backoff) before it can receive events again.

What I've already tried:

Client sends a ping every 20s to keep the connection alive

Server sends native ws.ping() every 30s

Set httpServer.keepAliveTimeout = 120000 and httpServer.headersTimeout = 125000 explicitly in Node (default is only 5s, meant for short HTTP requests)

Disconnections still happen with the same pattern after these changes

Questions:

Does Railway's proxy/load balancer have its own idle timeout for WebSocket connections that could override my Node keepAliveTimeout?

Is there a known WebSocket connection limit/duration issue on the Free plan specifically?

Any recommended ping interval or headers that have worked for others running WebSocket apps on Railway?

Has anyone run into this same pattern? Any pointers would help a lot, thanks!

$10 Bounty

1 Replies

Railway
BOT

17 days ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway 17 days ago


17 days ago

Hey,

  1. Railway has no timeouts for WebSocket connections, according to the docs: https://docs.railway.com/networking/public-networking/specs-and-limits#technical-specifications.
  2. No, the free plan has other limits, such as resource limits and credits, but none related to timeouts.

For your last two questions, we haven’t had any issues related to WebSockets from our users. This really points to an issue in your application. Doesn’t the WebSocket have error codes that could help investigate? Lastly, are you able to provide a reproducible example? That would help us debug it.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...