Fixes a race condition when disconnecting and immediately connecting
again. Also fixes disconnect() being called twice.
Let me be clear, I DO NOT LIKE THIS SOLUTION. I think it's dumb but I
don't see any other reasonable alternative. There isn't a way to
transfer state to a new connection state object and I can't think of a
nice way to do it either. That said, waiting an arbitrary amount of
time for an arbitrary websocket event doesn't seem like the right
solution either, but it's the best I can do at this point.