deno icon indicating copy to clipboard operation
deno copied to clipboard

Uncaught InvalidStateError: readyState not OPEN

Open oq-x opened this issue 2 years ago • 3 comments

this is my code:

  websocket.onmessage = async (ev) => {
    const data = JSON.parse(ev.data);
    if (data.s) s = data.s;
    switch (data.op) {
      case 1: {
        websocket.send(JSON.stringify({ op: 1, s: null }));
        break;
      }
      case 10: {
        setInterval(() => {
          websocket.send(JSON.stringify({ op: 1, s }));
        }, data.d.heartbeat_interval * Math.random());
        break;
      }
      case 0: {
        const event = events.get(data.t);
        if (!event) return;
        await event(data.d);
        break;
      }
    }
  };```

oq-x avatar Jan 29 '23 16:01 oq-x

are you getting a close event?

crowlKats avatar Jan 29 '23 16:01 crowlKats

yes

oq-x avatar Jan 29 '23 17:01 oq-x

from the looks of it, you have a set internal that you never clear, so the websocket closes and your interval still tries to send events

crowlKats avatar Jan 29 '23 17:01 crowlKats