#TIL 37 - How to fix Session ID unknown with socket.io

Feb 23, 2023 · Dung Huynh

What

Fix "Session ID unknown" errors in Socket.io deployments.

Why

HTTP long-polling requires sticky sessions. Without load balancer affinity, requests hit different servers causing session mismatch.

How

Disable HTTP long-polling, use WebSockets only:

// Client-side
const socket = io({
  transports: ["websocket"],
});

WebSockets maintain persistent connection, eliminating the need for sticky sessions.

Reference