Hi, I’m Dung Huynh Duc . Nice to meet you.

About Me

I’m a full stack developer. I’m a fast learner and self-taught coder. I often take my time for researching and learning about hot and trending technology.

Session ID unknown

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

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

If you're using Socket.io in your web application, you may encounter an issue where the Session ID is unknown. The solution is disabling HTTP long-polling and using only WebSockets for communication between the client and server.

// client-side
const socket = io({
  transports: ["websocket"] // HTTP long-polling is disabled

The root cause is enabling "sticky session" if HTTP long-polling is enabled (which is the default). You can read more about why sticky sessions are required and how to implement them in the Socket.io documentation: https://socket.io/docs/v4/using-multiple-nodes/#why-is-sticky-session-required