Using
Web-application. NodeJS + Socket.io (websockets only, heartbeats enabled).
Problem
My application works OK (it connects to Socket.io, it emits/receives messages correctly), but I detect random disconnections, not because of heartbeat timeouts. Even if the server receives a heartbeat packet from client it is still possible that it disconnects this client in a few seconds. And I do not understand the reason. It happens almost randomly, roughly each 3-15 minutes. Changing socket.io configuration does not seem to affect the frequency.
Here is the log and it clearly shows that the reason for disconnection is not heartbeat timeouts, but a transport end (socket end):
Log:
debug: emitting heartbeat for client cTVCsv2GS2R_lh3Ecao-
debug: websocket writing 2::
debug: set heartbeat timeout for client cTVCsv2GS2R_lh3Ecao-
debug: got heartbeat packet
debug: cleared heartbeat timeout for client cTVCsv2GS2R_lh3Ecao-
debug: set heartbeat interval for client cTVCsv2GS2R_lh3Ecao-
info: transport end (socket end)
// ^ Why?
debug: set close timeout for client cTVCsv2GS2R_lh3Ecao-
debug: cleared close timeout for client cTVCsv2GS2R_lh3Ecao-
debug: cleared heartbeat interval for client cTVCsv2GS2R_lh3Ecao-
SOCK 25.12 22:23:20.675 disconnection from IO detected (USER1)
// ^ This means disconnected event fired
debug: discarding transport
debug: client authorized
info: handshake authorized GPBLHsqhhrdsTeqTcao_
debug: setting request GET /socket.io/1/websocket/GPBLHsqhhrdsTeqTcao_?conftoken=20519986772
debug: set heartbeat interval for client GPBLHsqhhrdsTeqTcao_
debug: client authorized for
debug: websocket writing 1::
debug: client authorized for /io/activity
debug: websocket writing 1::/io/activity
SOCK 25.12 22:23:23.005 reconnected to IO (USER1)
Configuration
Client:
socket = io.connect('/io/activity',{'max reconnection attempts':Infinity})
Server:
io = require('socket.io').listen(server, {
log: true
, "close timeout": 120
, "heartbeat timeout": 120
, "heartbeat interval": 30
, "transports": ["websocket"]
})
io.enable('browser client minification')
io.enable('browser client etag')
io.enable('browser client gzip')