-
Couldn't load subscription status.
- Fork 10.1k
Description
I have a Socket.IO setup that works perfectly at first, but after several hours of uptime (sometimes ~3 hours, other times 1–2 days), the WebSocket connection suddenly drops. After that, the client tries to reconnect, but every attempt fails in a loop until I restart the server.
The browser console shows:
WebSocket connection to 'wss://test.com/socket.io/?userId=1&companyId=1&EIO=4&transport=websocket' failed: Invalid frame header
On the client, I log connection errors:
socket.io.on("reconnect_error", err => console.error("Error on trying to reconnect:", err));
socket.on("connect_error", err => console.error("Connect error:", err.message, err));
socket.on("disconnect", reason => console.warn("Socket disconnected:", reason));
But the only message I consistently get is:
Connect error: websocket error F: websocket error
After this point, the only way to recover is restarting the server.
socket.io: 4.8.1
socket.io-client: 4.8.1
@socket.io/redis-adapter: 8.3.0
redis: 5.8.2
Node (client): 16.20.2
Node (server): 20.12.2
Deployment: multiple pods behind Redis pub/sub
Server
io = new SocketIO(httpServer, {
adapter: createAdapter(pubClient, subClient),
cors: { origin: process.env.FRONTEND_URL },
pingInterval: 30000,
pingTimeout: 30000
});
Client
const socket = io(BACKEND_URL, {
autoConnect: false,
transports: ["websocket"],
reconnection: true,
query: { userId, companyId }
});
Expected behavior
Socket.IO should reconnect normally, not enter a permanent failure state until the entire server is restarted.