Skhmt / tapic

Twitch API & Chat. A javascript library for doing things with twitch chat, APIs, and pubsub. Can be used to make a HTML or Node.js bot. Or something.
MIT License
18 stars 5 forks source link

Error: Uncaught Exception at WebSocket #3

Closed WectonicG closed 7 years ago

WectonicG commented 7 years ago

I get randomly a error during runtime.

Uncaught Exception: Error: not opened at WebSocket.send

This comes everytime after max. 10 minutes.

Is this a known issue or what can I do against it?

Skhmt commented 7 years ago

Not sure, let me do some testing.

I'm guessing it has to do with pubsub's WebSocket connection since that's been acting finicky and disconnecting randomly.

WectonicG commented 7 years ago

A fix for this would be very nice :D

Skhmt commented 7 years ago

I've recreated it, not sure why it's happening but I'm investigating fixes now.

Skhmt commented 7 years ago

Fixed. I tightened up my error handling of the randomly unstable Twitch pubsub socket, especially when sending messages. I also did a better job at clearing the pubsub internal state and disconnecting gracefully before reconnecting.

What was causing the error was not resetting "onclose" handler on the pubsub websocket connection to an empty function before closing it - this caused it to reopen immediately when I was already in the process of opening it. This caused a bunch of sockets to open until the max of ~100 or so was hit, which then started to massively leak memory in Chrome. This also caused the error you found, although you saw the early stages and probably not the memory leak.

WectonicG commented 7 years ago

thanks :)