Discord bot silently fails after several hours

Hi all,

I’ve deployed 3 Discord bots written in TypeScript (Deno) to the service over the last few days. Each bot seems to disconnect from Discord after a while - usually after 3-4 hours, but sometimes much longer. Due to not having an HTTP endpoint to hit, I’m not currently making use of health checks.

On the most recent restarts of one of the apps, I added a log statement to tick every 5 minutes. I see those statements regularly for ~4.5 hours:

2023-05-06T01:13:08.565 app[6e82d4d6c00568] lax [info] Health tick
<... regular 5 min logs ...>
2023-05-06T05:38:08.625 app[6e82d4d6c00568] lax [info] Health tick
<... nothing until manual app restart ...>
2023-05-06T18:35:52.648 app[6e82d4d6c00568] lax [info] Sending signal SIGINT to main child process w/ PID 513
2023-05-06T18:35:53.560 app[6e82d4d6c00568] lax [info] Starting clean up.
2023-05-06T18:35:54.562 app[6e82d4d6c00568] lax [info] [62595.354941] reboot: Restarting system

Version of the CLI: flyctl v0.0.558 linux/amd64 Commit: 44f30c48 BuildDate: 2023-05-05T21:53:05Z. I’m running on a single machine. Memory usage is about 85MB.

I absolutely accept that I may be doing something incorrectly with my fly.io configuration! The code is on GitHub, here, and my fly.toml is very simple:

app = "celeo-gandalf-bot"
primary_region = "lax"

I’ve read through many posts on these forums and articles across the web about deploying Discord bots here, and I haven’t read about any hidden complexity or similar. I would quickly blame my code, but these bots have been running on another provider’s VPS for years without this issue.

I’ve played around with adding a simple HTTP endpoint for health checks, but that would only cover the problem, not truly fix it.

Any advice is much appreciated!

EDIT: the apps have been stable for 48hrs, and I’ve made some changes, so perhaps everything is fine.

I’m running a Discord bot that’s online 24/7 and have never seen any unexpected downtime. Are you using discord.js, or using your own library?

Hi! I’m using this library, discordeno. It could be an issue with the library, but it’s odd that I hadn’t seen this issue running on other platforms.

Depending on your code, you might want to add more logging to make sure you’re not swallowing an error somewhere that causes your client to crash.

Here’s a bot that’s running correctly:

And here’s the one that’s currently “dead”:

image

It’s certainly … running.

Under 1% CPU for a long time, then …

8:31:15 … 3%
8:31:30 … 37%
8:31:45 … 54%
8:32:00 … 87%
8:32:15 … 100%

and pinned there since.

Runaway recursion? Stuck event loop? Who knows. The memory usage hasn’t increased at all.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.