tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 215 forks source link

Check websocket connecting readyState #338

Closed instafluff closed 5 years ago

instafluff commented 5 years ago

On reconnects with large numbers of channels, the queue join can mess up and try to send WS messages before the state is actually set to "CONNECTED" causing a crash. This PR checks for "CONNECTING" states.

Related issue: https://github.com/tmijs/tmi.js/issues/217

instafluff commented 5 years ago

Crash error message looks like this:

(node:29509) UnhandledPromiseRejectionWarning: No response from Twitch.
(node:29509) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:29509) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
/home/bitnami/Gabby/node_modules/tmi.js/node_modules/ws/lib/websocket.js:328
      throw err;
      ^

Error: WebSocket is not open: readyState 0 (CONNECTING)
    at WebSocket.send (/home/bitnami/Gabby/node_modules/tmi.js/node_modules/ws/lib/websocket.js:322:19)
    at client.<anonymous> (/home/bitnami/Gabby/node_modules/tmi.js/lib/client.js:182:37)
    at queue.next (/home/bitnami/Gabby/node_modules/tmi.js/lib/timer.js:30:8)
    at Timeout.setTimeout [as _onTimeout] (/home/bitnami/Gabby/node_modules/tmi.js/lib/timer.js:32:14)
    at ontimeout (timers.js:424:11)
    at tryOnTimeout (timers.js:288:5)
    at listOnTimeout (timers.js:251:5)
    at Timer.processTimers (timers.js:211:10)