Fix onclose timeout

This is a fix for 1206. The onclose on the socket is getting erroneously called. This fixes the issue of buffer taking precedence.

I don't think this is an ultimate solution, for that we need to plan on removing socket.io. This will give us time to not rush that though.