Ensure _cleanUp is called when socket closed unexpectedly
Fix infinite loop in onclose -> cleanUp -> close -> onclose -> cleanUp -> ...