Replit realtime

Replit WebSocket Proxy Disconnecting

Your real-time features (chat, live updates, notifications) stop working after a few minutes because WebSocket connections are silently dropped. Users see stale data and must refresh the page to get updates again.

Replit routes WebSocket traffic through a reverse proxy that has idle connection timeouts. If no data is sent over the WebSocket for a period of time, the proxy closes the connection. Your app has no reconnection logic, so the connection stays dead until the user refreshes.

This is especially problematic for apps that use WebSockets for occasional updates (like notifications) rather than constant data streams. The connection sits idle between updates and gets killed by the proxy.

Error Messages You Might See

WebSocket connection to 'wss://...' failed WebSocket is already in CLOSING or CLOSED state Error during WebSocket handshake: Unexpected response code: 502 Connection closed abnormally (code 1006)
WebSocket connection to 'wss://...' failedWebSocket is already in CLOSING or CLOSED stateError during WebSocket handshake: Unexpected response code: 502Connection closed abnormally (code 1006)

Common Causes

  • Proxy idle timeout — Replit's reverse proxy closes WebSocket connections that are idle for too long (typically 60 seconds)
  • No ping/pong heartbeat — the app does not send periodic keep-alive messages to prevent timeout
  • No reconnection logic — when the connection drops, the client does not attempt to reconnect
  • Container sleep — Replit free tier containers sleep after inactivity, killing all connections
  • SSL/TLS handshake issues — WebSocket upgrade fails intermittently through the HTTPS proxy

How to Fix It

  1. Implement ping/pong heartbeat — send a ping message every 30 seconds from the server and respond with pong from the client
  2. Add client-side reconnection — detect disconnection and automatically reconnect with exponential backoff
  3. Use a WebSocket library with built-in reconnection — libraries like socket.io or reconnecting-websocket handle this automatically
  4. Handle connection state in UI — show a "reconnecting" indicator when the WebSocket is disconnected
  5. Use wss:// not ws:// — Replit requires secure WebSocket connections since it serves over HTTPS

Real developers can help you.

Simon A. Simon A. I'm a backend developer building APIs, emulators, and interactive game systems. Professionally, I've developed Java/Spring reporting solutions, managed relational and NoSQL databases, and implemented CI/CD workflows. Tejas Chokhawala Tejas Chokhawala Full-stack engineer with 5 years experience building production web apps using React, Next.js and TypeScript. Focused on performance, clean architecture and shipping fast. Experienced with Supabase/Postgres backends, Stripe billing, and building AI-assisted developer tools. Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting. PawelPloszaj PawelPloszaj I'm fronted developer with 10+ years of experience with big projects. I have small backend background too Krishna Sai Kuncha Krishna Sai Kuncha Experienced Professional Full stack Developer with 8+ years of experience across react, python, js, ts, golang and react-native. Developed inhouse websearch tooling for AI before websearch was solved : ) Victor Denisov Victor Denisov Developer MFox MFox Full-stack professional senior engineer (15+years). Extensive experience in software development, qa, and IP networking. Matthew Jordan Matthew Jordan I've been working at a large software company named Kainos for 2 years, and mainly specialise in Platform Engineering. I regularly enjoy working on software products outside of work, and I'm a huge fan of game development using Unity. I personally enjoy Python & C# in my spare time, but I also specialise in multiple different platform-related technologies from my day job. Stanislav Prigodich Stanislav Prigodich 15+ years building iOS and web apps at startups and enterprise companies. I want to use that experience to help builders ship real products - when something breaks, I'm here to fix it. Matthew Butler Matthew Butler Systems Development Engineer @ Amazon Web Services

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

How often should I send heartbeat pings?

Every 25-30 seconds is a safe interval. This keeps the connection alive through most proxy timeout configurations without creating excessive traffic.

Should I use WebSocket or socket.io on Replit?

socket.io is recommended because it includes automatic reconnection, heartbeats, and fallback to HTTP long-polling when WebSockets are unavailable.

Do WebSockets work on Replit free tier?

Yes, but the free tier containers sleep after inactivity. When the container sleeps, all WebSocket connections are dropped. Paid deployments stay active.

Related Replit Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help