lumeland / lume

🔥 Static site generator for Deno 🦕
https://lume.land
MIT License
1.75k stars 74 forks source link

InvalidStateError: readyState not OPEN #614

Closed iacore closed 3 weeks ago

iacore commented 3 weeks ago

Version

v2.2.1

Platform

Linux

What steps will reproduce the bug?

  1. deno task serve
  2. modify a page, save a page, modify the same page, save the same page. do this very fast

How often does it reproduce? Is there a required condition?

the crash is probabilistic. the faster you do the sequence of actions, the more likely that deno will crash.

What is the expected behavior?

No crash

What do you see instead?

error: Uncaught (in promise) InvalidStateError: readyState not OPEN
    sockets.forEach((socket) => socket.send(message));
                                       ^
    at WebSocket.send (ext:deno_websocket/01_websocket.js:326:13)
    at https://deno.land/x/lume@v2.2.1/middlewares/reload.ts:24:40
    at Set.forEach (<anonymous>)
    at https://deno.land/x/lume@v2.2.1/middlewares/reload.ts:24:13
    at Events.dispatchEvent (https://deno.land/x/lume@v2.2.1/core/events.ts:46:19)
    at SiteWatcher.dispatchEvent (https://deno.land/x/lume@v2.2.1/core/watcher.ts:155:24)
    at https://deno.land/x/lume@v2.2.1/core/watcher.ts:166:12
    at Events.dispatchEvent (https://deno.land/x/lume@v2.2.1/core/events.ts:46:19)
    at Site.dispatchEvent (https://deno.land/x/lume@v2.2.1/core/site.ts:272:24)

Additional information

seems to be a race condition

oscarotero commented 3 weeks ago

Hmm. WebSockets are added to the sockets list only when they are open, and removed on close (See code here)

So perhaps a socket is closed and, before being removed of the sockets list, the send method is invoked.

Can you try changing this line adding an if to check if the socket is already open?