Closing socket connection with XHR-polling

Does anyone know why my socket connection does not close when using xhr-polling? This is the server code I would like to execute, but does not fire when using xhr-polling. The socket connection works fine ( I am running behind varnish with stunnel, since this a secure socket). I tried manually emitting a disconnect event on the browser unload, but this isnt an optimal solution for me.

client.on('disconnect', function () {

    delete connected_clients[id];
    console.log('   debug - ' + 'client ' + client.id + 'is disconnected');
    console.log('   debug - ' + 'total number of connected clients is ' + Object.keys(connected_clients).length);               

});

In my client side code, I am connecting the socket like this:

socket = io.connect(BASE_URL, {
    "sync disconnect on unload":true
});

and my server side settings are this:

    io.enable('browser client minification');  // send minified client
    io.enable('browser client etag');          // apply etag caching logic based on version number
    io.enable('browser client gzip');          // gzip the file
    io.set('log level', 3);                    // reduce logging
    io.set('match origin protocol', true);     // ssl support
    io.set('sync disconnect on unload', true);
    io.set('transports', [                     // enable all transports (optional if you want flashsocket)
        'xhr-polling',
        'websocket',
        'flashsocket',
        'htmlfile',
        'jsonp-polling'
    ]);  

This is the debug message I get when the client exits the browser

debug: xhr-polling closed due to exceeded duration

I am using socket.io version 0.9.10 with node 0.8.8.

Since the connection is between you (the server) and the client (the browser), you are at the mercy of the browser in regards to being notified of when the connection closes. If the browser does not notify you of that it considers the connection to be closed, then there is no way for you to be informed about it.

I suggest that you program your client to behave in a way that treats your server nicely, notifying it when the connection is discarded appropriately. In cases when the connection is simply neglected without notification, you simply close the connection after a certain period of time of inactivity (timeout).

Think of it like the scenario of when you are instant messaging a friend. Your friend may be kind enough to notify you of that they are leaving their desk and no longer are able to attend the conversation (disconnect), or they could also just leave their desk without notification (kill browser process), or worse, they could be having a heart attack that would disable them from attending (power outage). You will understand after a while that they are no longer actively participating in the session (timeout).

I'm sorry, there is just no magic here. You have to program your server to deal with the fact that it may be talking to a disconnected client.