Ensure _cleanUp is called when socket closed unexpectedly

_cleanUp wasn't being called in the socket's onclose handler, which meant the heartbeat intervals weren't stopped properly when the socket closed unexpectedly.