lua
DIAdiscord.js - Imagine an app
•Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
I have developed a simple bot that:
1. Detects when a message could possibly contain media/embeds
2. Reacts with up/down arrows, an "upvote bot"
And it works great! It's very funny and useful for my Discord community named "MNSND".
However, after a significant amount of time (anywhere from 1 to 24 hours), the bot becomes unresponsive and starts missing messages. I do not believe this to be a Discord.js issue directly, but possibly an issue with my code and how it interacts with Discord.js and the Node.js runtime. It's really weird!
Here is the exact current source code and package.json: https://gist.github.com/luavixen/bb8f52535a0f8c8a958bdc41773b642d
To be specific, it seems like the Node.js event loop is getting "clogged" or "locked up"? After a significant amount of time, the Node.js process fails to even perform basic asynchronous actions. After even longer, I cannot even terminate the process, I must send a SIGKILL signal.
For example, I tried introducing a setTimeout call on program start that, after four hours, prints a message and calls process.exit. This would only ever complete 50% of the time on my development machine!
I have reproduced this issue on:
1. Development machine - Windows 11 Laptop - Node.js v20.17.0
2. My personal server - Ubuntu LTS 20.04, hosted on my own hardware - Node.js v18.12.0
3. DigitalOcean droplet - Ubuntu LTS latest - Node.js Docker node:20-alpine
To try and mitigate this issue, I put the bot inside of docker:
And created this cronjob:
Even still, the bot occasionally locks up and misses messages. It is completely unpredictable. Sometimes, Docker can simply ask the bot to gracefully shut down:
But sometimes, after the bot locks up, Docker must send a SIGKILL:
I have been working with Node.js for years and years, and I am kinda stumped. Help!
15 replies