avatarkava / beavisbot

A node.js powered bot for plug.dj and dubtrack.fm
https://github.com/avatarkava/beavisbot/wiki
MIT License
22 stars 20 forks source link

PM2 questions, general uptime advice #121

Closed FranciscoG closed 7 years ago

FranciscoG commented 7 years ago

hey I have my own bot, not based on BeavisBot, but another one. I'm also using PM2 to manage my process. I had a couple questions that I hope you could answer or at least point me in the right direction. I should say that I know JS but I'm newer to running a node server, I've mostly done front-end JS or back-end C#/PHP

I'm running the bot on a Pi and I'm using PM2 and I was using the default settings. I'm considering eventually to move to Digital Ocean droplet but for now the Pi is doing pretty well.

What's your PM2 setup? is it just what I see in your Readme?

Do you find that you encounter Ably WebSocket errors a lot? I think this ends up crashing my bot eventually cause I max out the maxRestarts of PM2. So I might need to increase those

Basically I'm just curious what you might be doing to ensure uptime. I feel like once a day my bot goes down completely and I'm trying to figure out how to stop that.

examples of some errors I get often

2016-10-06 18:09:59:572 [Error]     [BOT]           DubAPIRequestError: Response 400 from room/55ff1ad54c828c03008bd5e2/playlist/57ebfa3be9c39647003c1be4/dubs
2016-10-06 18:10:29:701 [Error]     [BOT]           DubAPIRequestError: Response 400 from room/55ff1ad54c828c03008bd5e2/playlist/details
2016-10-06 18:10:29:806 [Error]     [BOT]           DubAPIRequestError: Response 400 from room/55ff1ad54c828c03008bd5e2/users
2016-10-06 18:10:29:904 [Error]     [BOT]           DubAPIRequestError: Response 400 from room/%RID%/users
2016-10-06 18:17:28:374 [Error]     [BOT]           TypeError: Cannot read property 'playTimeout' of undefined
    at DubAPI.updatePlay (~/DerpyBot/node_modules/dubapi/lib/actionHandler.js:59:29)
    at Timer.listOnTimeout (timers.js:92:15)
2016-10-06 18:17:28:375 [Warning]   [Logger]        Check syntax, something was undefined - Severity: error Source: BOT Message: undefined
Ably: WebSocketTransport.onWsData(): Unexpected exception handing channel message: TypeError: Cannot read property '_id' of undefined
    at new MediaModel (~/DerpyBot/node_modules/dubapi/lib/models/mediaModel.js:8:19)
    at DubAPI.EventHandler (~/DerpyBot/node_modules/dubapi/lib/eventHandler.js:166:26)
    at Object.boundFunc (~/DerpyBot/node_modules/dubapi/lib/utils.js:11:21)
    at EventEmitter.emit (~/DerpyBot/node_modules/ably/common/lib/util/eventemitter.js:145:16)
    at RealtimeChannel.onEvent (~/DerpyBot/node_modules/ably/common/lib/client/realtimechannel.js:109:18)
    at RealtimeChannel.onMessage (~/DerpyBot/node_modules/ably/common/lib/client/realtimechannel.js:328:9)
    at Channels.onChannelMessage (~/DerpyBot/node_modules/ably/common/lib/client/realtime.js:53:11)
    at ConnectionManager.onChannelMessage (~/DerpyBot/node_modules/ably/common/lib/transport/connectionmanager.js:1275:27)
    at WebSocketTransport.Transport.onProtocolMessage (~/DerpyBot/node_modules/ably/common/lib/transport/transport.js:112:27)
    at WebSocketTransport.onWsData (~/DerpyBot/node_modules/ably/common/lib/transport/websockettransport.js:90:9)
Ably: WebSocketTransport.onWsData(): Unexpected exception handing channel message: TypeError: Cannot read property '_id' of undefined
    at new PlayModel (~/DerpyBot/node_modules/dubapi/lib/models/playModel.js:6:19)
    at DubAPI.EventHandler (~/DerpyBot/node_modules/dubapi/lib/eventHandler.js:197:20)
    at Object.boundFunc (~/DerpyBot/node_modules/dubapi/lib/utils.js:11:21)
    at EventEmitter.emit (~/DerpyBot/node_modules/ably/common/lib/util/eventemitter.js:145:16)
    at RealtimeChannel.onEvent (~/DerpyBot/node_modules/ably/common/lib/client/realtimechannel.js:109:18)
    at RealtimeChannel.onMessage (~/DerpyBot/node_modules/ably/common/lib/client/realtimechannel.js:328:9)
    at Channels.onChannelMessage (~/DerpyBot/node_modules/ably/common/lib/client/realtime.js:53:11)
    at ConnectionManager.onChannelMessage (~/DerpyBot/node_modules/ably/common/lib/transport/connectionmanager.js:1275:27)
    at WebSocketTransport.Transport.onProtocolMessage (~/DerpyBot/node_modules/ably/common/lib/transport/transport.js:112:27)
    at WebSocketTransport.onWsData (~/DerpyBot/node_modules/ably/common/lib/transport/websockettransport.js:90:9)
Ably: WebSocketTransport.onWsData(): Unexpected exception handing channel message: TypeError: Cannot set property '_user' of undefined
    at DubAPI.EventHandler (~/DerpyBot/node_modules/dubapi/lib/eventHandler.js:31:28)
    at Object.boundFunc (~/DerpyBot/node_modules/dubapi/lib/utils.js:11:21)
    at EventEmitter.emit (~/DerpyBot/node_modules/ably/common/lib/util/eventemitter.js:145:16)
    at RealtimeChannel.onEvent (~/DerpyBot/node_modules/ably/common/lib/client/realtimechannel.js:109:18)
    at RealtimeChannel.onMessage (~/DerpyBot/node_modules/ably/common/lib/client/realtimechannel.js:328:9)
    at Channels.onChannelMessage (~/DerpyBot/node_modules/ably/common/lib/client/realtime.js:53:11)
    at ConnectionManager.onChannelMessage (~/DerpyBot/node_modules/ably/common/lib/transport/connectionmanager.js:1275:27)
    at WebSocketTransport.Transport.onProtocolMessage (~/DerpyBot/node_modules/ably/common/lib/transport/transport.js:112:27)
    at WebSocketTransport.onWsData (~/DerpyBot/node_modules/ably/common/lib/transport/websockettransport.js:90:9)
    at WebSocket.wsConnection.onmessage (~/DerpyBot/node_modules/ably/common/lib/transport/websockettransport.js:68:50)
avatarkava commented 7 years ago

Really I'm just using a stock ubuntu package for pm2, so not much in the way of config. That said, the issues look to be tied more to Ably implementation on DubAPI than anything concerning pm2, and I see you have a ticket open over there already.

My community's over on plug.dj again, so personal dev on dubtrack.fm stuff is pretty much halted for the foreseeable future again.

I'd check to make sure you are using the newest version of plugAPI (npm update) - it looks like there were some updates to the implementation of Ably as recently as Sep 9. Absent that, your ticket on dubAPI is probably where you're going to actually get this solved as it seems to be a bug in the library itself.

FranciscoG commented 7 years ago

I am at the newest version of the DubApi. I was just wondering if there some optimal PM2 settings to compensate for the issues since they switched over to Ably (like increasing max restarts, adding a timeout between restarts, increasing memory, etc). But

I think it's just that Ably sucks compared to PubNub. Oh well, you get what you pay for I guess. (assuming the switch to Ably was to save money)

anyways, thanks and I'll keep checking in on the DubApi issue. 👍 🎃

avatarkava commented 7 years ago

Got it. May want to look here: http://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/

You can add flags like --max-restarts, though if you're getting that many you may not be able to get out of it.

Another approach might be forcing an older release of DubAPI in your package.json - something like this:

"dubapi": "git://github.com/anjanms/DubAPI.git#v1.6.2",

https://github.com/anjanms/DubAPI/releases