Fix close event handler in case the client disconnects before a WebSocket connection has been established