When I tested setting an invalid URL, the behavior I see on the websocket is onopen is never called, it calls onerror and then onclose. So it can happen that onclose is called without calling onopen