Disconnect event gets fired 2 minutes later

I'm using Node.JS and Socket.IO to create a chat, I use XHR polling with a duration of 10 to host it on Heroku.

When I leave the page with my client, I'd like to calll the disconnect method automatically on the server which removes it from other clients. It's in fact done but... 2 minutes after the client has really left the page, which is quite awkward.

Is there a way to call the disconnect method as soon as the client doesn't reply ? Or at least being a little faster to know when the client is not there anymore ?

I've tried to close the socket client-side on page exit with jQuery but it doesn't work. The problem is that using socket.disconnect() is asynchronous and non-blocking and the user leaves before the request is completed...

You can play with heartbeat timeout, heartbeat interval and close timeout values of socket.io configuration.

Search for heartbeat and timeout in this page: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

If you set the 'sync disconnect on unload' option on the socket.io client to true, it will send a synchronous xhr disconnect request in onbeforeunload that will disconnect the socket.