eris: ERR_UNHANDLED_ERROR after updating to 0.11.2

I seem to have run into an unusual issue after updating from 1.10.1 to 1.11.2. Seemingly out of nowhere, the bot sometimes throws this connection error, causing my game server to crash and restart.

[5022.558]: [INFO] An unnamed player rejoined the game! IP: ::ffff:37.192.190.132. Player ID: 464148. Players: 1.
[5068.763]: [INFO] An unnamed player has disconnected! IP: ::ffff:37.192.190.132. Players: 0.
events.js:288
      throw er; // Unhandled 'error' event
      ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (ErrorEvent {
  target: WebSocket {
    _events: [Object: null prototype] {
      open: [Function],
      message: [Function],
      error: [Function]
    },
    _eventsCount: 3,
    _maxListeners: undefined,
    readyState: 2,
    protocol: '',
    _binaryType: 'nodebuffer',
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: '',
    _closeTimer: null,
    _closeCode: 1006,
    _extensions: {},
    _receiver: null,
    _sender: null,
    _socket: null,
    _bufferedAmount: 0,
    _isServer: false,
    _redirects: 0,
    url: 'wss://gateway.discord.gg/?v=6&encoding=json',
    _req: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      connection: [TLSSocket],
      _header: 'GET /?v=6&encoding=json HTTP/1.1\r\n' +
        'Sec-WebSocket-Version: 13\r\n' +
        'Sec-WebSocket-Key: 3ngaXVhxFWt4sVeV0Ypl1Q==\r\n' +
        'Connection: Upgrade\r\n' +
        'Upgrade: websocket\r\n' +
        'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n' +
        'Host: gateway.discord.gg\r\n' +
        '\r\n',
      _onPendingData: [Function: noopPendingOutput],
      agent: undefined,
      socketPath: undefined,
      method: 'GET',
      insecureHTTPParser: undefined,
      path: '/?v=6&encoding=json',
      _ended: false,
      res: null,
      aborted: true,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: [HTTPParser],
      maxHeadersCount: null,
      reusedSocket: false,
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    [Symbol(kCapture)]: false
  },
  type: 'error',
  message: 'WebSocket was closed before the connection was established',
  error: Error: WebSocket was closed before the connection was established
      at WebSocket.terminate (/home/arras/arras.io/node_modules/eris/node_modules/ws/lib/websocket.js:366:14)
      at Shard.disconnect (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:98:25)
      at Timeout._onTimeout (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:1684:22)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7)
})
    at Client.emit (events.js:300:17)
    at Shard.emit (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:1888:26)
    at WebSocket.ws.onerror (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:1632:18)
    at WebSocket.onError (/home/arras/arras.io/node_modules/eris/node_modules/ws/lib/event-target.js:128:16)
    at WebSocket.emit (events.js:311:20)
    at abortHandshake (/home/arras/arras.io/node_modules/eris/node_modules/ws/lib/websocket.js:697:15)
    at WebSocket.terminate (/home/arras/arras.io/node_modules/eris/node_modules/ws/lib/websocket.js:366:14)
    at Shard.disconnect (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:98:25)
    at Timeout._onTimeout (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:1684:22)
    at listOnTimeout (internal/timers.js:549:17)
Emitted 'error' event on Client instance at:
    at Shard.emit (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:1888:26)
    at Shard.disconnect (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:109:18)
    at Timeout._onTimeout (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:1684:22)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) {
  code: 'ERR_UNHANDLED_ERROR',
  context: ErrorEvent {
    target: WebSocket {
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      readyState: 2,
      protocol: '',
      _binaryType: 'nodebuffer',
      _closeFrameReceived: false,
      _closeFrameSent: false,
      _closeMessage: '',
      _closeTimer: null,
      _closeCode: 1006,
      _extensions: {},
      _receiver: null,
      _sender: null,
      _socket: null,
      _bufferedAmount: 0,
      _isServer: false,
      _redirects: 0,
      url: 'wss://gateway.discord.gg/?v=6&encoding=json',
      _req: [ClientRequest],
      [Symbol(kCapture)]: false
    },
    type: 'error',
    message: 'WebSocket was closed before the connection was established',
    error: Error: WebSocket was closed before the connection was established
        at WebSocket.terminate (/home/arras/arras.io/node_modules/eris/node_modules/ws/lib/websocket.js:366:14)
        at Shard.disconnect (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:98:25)
        at Timeout._onTimeout (/home/arras/arras.io/node_modules/eris/lib/gateway/Shard.js:1684:22)
        at listOnTimeout (internal/timers.js:549:17)
        at processTimers (internal/timers.js:492:7)
  }
}
[0.367]: 6100 x 6100 room initalized. Max food: 149. Max nest food: 4.
...

Currently, I use WebSocket version 7.2.3, though it seemed to work fine with 1.10.1. I’ve also noticed how the bot seemingly looses connection at random without crashing the server, instead running bot.on("ready".... I’m not sure if that is normal behavior, but here’s an image to represent a few times the bot has done this: Capture So yeah, that’s quite a mouthful. Haven’t found any issues similar to this, so here I am. Maybe this is just an easy fix that’s been hiding under my nose, but I haven’t been able to find it.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Wrong, handle the error event (in this case from the Client)