0

I have had a Bot hosted on Heroku for about 3 months. The bot uses node.js and interacts with a Discord server. Last night the bot crashed and created serveral logs entries (see below). My question is what caused this crash? Is there something I could have done to prevent it? Can I do something so Heroku can restart the bot? Thanks for any insight.

Apr 23 22:48:24 mhanndalorian-bot app/worker.1 events.js:301
Apr 23 22:48:24 mhanndalorian-bot heroku/worker.1 State changed from crashed to starting
Apr 23 22:48:24 mhanndalorian-bot heroku/worker.1 State changed from up to crashed
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     throw err; // Unhandled 'error' event
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     ^
Apr 23 22:48:24 mhanndalorian-bot app/worker.1 
Apr 23 22:48:24 mhanndalorian-bot app/worker.1 Error [ERR_UNHANDLED_ERROR]: Unhandled error. (ErrorEvent {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   target: WebSocket {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _events: [Object: null prototype] {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       message: [Function],
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       open: [Function],
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       error: [Function],
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       close: [Function]
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     },
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _eventsCount: 4,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _maxListeners: undefined,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     readyState: 2,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     protocol: '',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _binaryType: 'nodebuffer',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _closeFrameReceived: false,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _closeFrameSent: false,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _closeMessage: '',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _closeTimer: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _closeCode: 1006,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _extensions: {},
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _receiver: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _sender: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _socket: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _isServer: false,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _redirects: 0,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     url: 'wss://gateway.discord.gg/?v=6&encoding=json',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     _req: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     [Symbol(kCapture)]: false
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   },
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   type: 'error',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   message: 'connect ETIMEDOUT 162.159.134.234:443',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   error: Error: connect ETIMEDOUT 162.159.134.234:443
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     errno: 'ETIMEDOUT',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     code: 'ETIMEDOUT',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     syscall: 'connect',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     address: '162.159.134.234',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     port: 443
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   }
Apr 23 22:48:24 mhanndalorian-bot app/worker.1 })
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at Client.emit (events.js:299:17)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at WebSocketConnection.onError (/app/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:377:17)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at WebSocket.onError (/app/node_modules/ws/lib/event-target.js:128:16)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at WebSocket.emit (events.js:310:20)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at ClientRequest.<anonymous> (/app/node_modules/ws/lib/websocket.js:568:15)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at ClientRequest.emit (events.js:310:20)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at TLSSocket.socketErrorListener (_http_client.js:426:9)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at TLSSocket.emit (events.js:310:20)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at emitErrorNT (internal/streams/destroy.js:92:8)
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   code: 'ERR_UNHANDLED_ERROR',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   context: ErrorEvent {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     target: WebSocket {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _events: [Object: null prototype],
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _eventsCount: 4,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _maxListeners: undefined,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       readyState: 2,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       protocol: '',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _binaryType: 'nodebuffer',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _closeFrameReceived: false,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _closeFrameSent: false,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _closeMessage: '',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _closeTimer: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _closeCode: 1006,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _extensions: {},
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _receiver: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _sender: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _socket: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _isServer: false,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _redirects: 0,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       url: 'wss://gateway.discord.gg/?v=6&encoding=json',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       _req: null,
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       [Symbol(kCapture)]: false
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     },
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     type: 'error',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     message: 'connect ETIMEDOUT 162.159.134.234:443',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     error: Error: connect ETIMEDOUT 162.159.134.234:443
Apr 23 22:48:24 mhanndalorian-bot app/worker.1         at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       errno: 'ETIMEDOUT',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       code: 'ETIMEDOUT',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       syscall: 'connect',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       address: '162.159.134.234',
Apr 23 22:48:24 mhanndalorian-bot app/worker.1       port: 443
Apr 23 22:48:24 mhanndalorian-bot app/worker.1     }
Apr 23 22:48:24 mhanndalorian-bot app/worker.1   }
Apr 23 22:48:24 mhanndalorian-bot app/worker.1 }
Apr 23 22:48:24 mhanndalorian-bot heroku/worker.1 Process exited with status 1
Apr 23 22:48:29 mhanndalorian-bot heroku/worker.1 Starting process with command `node bot.js`
Apr 23 22:48:29 mhanndalorian-bot heroku/worker.1 State changed from starting to up
Apr 23 22:50:41 mhanndalorian-bot app/worker.1 (node:4) UnhandledPromiseRejectionWarning: Error: connect ETIMEDOUT 162.159.130.233:443
Apr 23 22:50:41 mhanndalorian-bot app/worker.1     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Apr 23 22:50:41 mhanndalorian-bot app/worker.1 (node:4) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Apr 23 22:50:41 mhanndalorian-bot app/worker.1 (node:4) [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.
  • What's the primary loop of the bot? Presumably, you could Promise.catch and restart when it catches an error. – sfdcfox Apr 24 at 13:04
  • The Application is restarted automatically when it crashes, see the last 7 lines that server is restarting and crashing. From the log it looks like the bot is not able to call discord server which can be due to anything, wrong URL, rate limiting by discord. The best way would be to use an error handler in promises or a try catch with async/await and see the error. – manjit5190 Apr 24 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.