Skip to content
Advertisement

Client Socket.io disconnects and reconnects to websocket persistently

I am connected via Socket.io 1.3.4 (via websockets) to the NodeJS server and client socket.io fires up “disconnect” event 5-30 seconds.

Every “disconnect”->”reconnecting”->”reconnect” iteration takes approx. 2 seconds. I am connected via cable to pretty stable network. Server is hosted on AWS.

Sometimes I have bad Wi-Fi connection, but no “disconnect” event fire up at all.

  1. How can I debug this issue?

  2. How can I see who is guilty – server or client?

  3. How does socket.io understands that it is time to disconnect? Could not understand this from their code.

Edit. Socket.io config:

io = require('socket.io')(server, { 
      log: false
    , "close timeout": 60
    , "heartbeat timeout": 60
    , "heartbeat interval": 20
})

Advertisement

Answer

I had a similar issue with nginx running in front of node, and it was because proxy_read_timeout and proxy_send_timeout were set too low. Socket.io sends heartbeats every 25 seconds, so make sure you set those timeouts to something greater than 25s.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement