#Memory leak in discord js

27 messages · Page 1 of 1 (latest)

calm vigil
#

I am currently facing a problem with a memory leak. I don't quite think it's related to discord.js, nevertheless I would like to ask if there are any common mistakes you can make with discord.js that lead to a memory leak. Or are there any other known problems with discord.js that lead to memory leaks?

silver starBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
hybrid talon
ancient shuttle
#

i just had a similar ish issue and it seems sweepers/ cache settings helped

keen cave
#

They don’t help with memory leaks. They only help with memory usage reduction

dense karma
#

.-. I'm having the same problem with v14.14.x
currently trying to trace it down, but using 637e1a4ddb6d5810deb31c5b90400ca277218270 is fine, 2d63d935581a953118e7cff9cb1ab6347f4ba3c3 is not (after the v14.14.x release)

dense karma
dense karma
# dense karma .-. I'm having the same problem with v14.14.x currently trying to trace it down,...

and the problem is in either discord.js, @discordjs/util or @discordjs/rest because I only pull those from GitHub
don't have much more info other than it happening randomly after a few hours after the bot started 🤷
And the amount the memory increases by is random, sometimes it's at the limit within a hour, sometimes it takes three hours to reach it
Well and it doesn't seem to affect smaller bots with less members/intents to cache I suppose? At least my other bots haven't seen a real change in memory usage

keen cave
# dense karma and the problem is in either `discord.js`, `@discordjs/util` or `@discordjs/rest...

May I suggest https://blog.appsignal.com/2020/05/06/avoiding-memory-leaks-in-nodejs-best-practices-for-performance.html which is what helped me with diagnosing memory leaks in bot code. That together with chrome dev tools to connect to node profiler and see what actually uses memory (best to compare two memory snapshots with it to find out what actually was added in that increase)

AppSignal Blog

Discover what memory leaks are and how to avoid them in your Node.js application.

dense karma
#

I'll give it a full read later, tho I've already tried created a heap dump before a memory leak started and the process crashed while creating it due to reaching the memory limit
I haven't tried things like --inspect yet, tho I generally want to avoid them because I can easily mess up something, causing the process to abort which would be bad

#

Changes in the process management code require a full restart of the whole server which is something I don't want to do often
As long as I don't have to use the latest djs version, I'll just try finding the commit which started breaking it

dense karma
#

Nope, that guide doesn't help me at all because the issue is not in my code xD

dense karma
#

I was able to create a heap dump now using the heapdump package, I'll try creating another one once memory starts leaking again

keen cave
lapis valley
#

Hey @keen cave, ive been having similar issues and saw the link you sent has AppSignal. Have you ever used it? I'm struggling to install it myself and would like some help if you have any knowledge with that

keen cave
#

No I didn’t. That’s a promo article for that but I ignore promo parts and only care about the rest of the article

dense karma
lapis valley
#

What even is that long string?

keen cave
#

A commit hash

lapis valley
#

ahh

dense karma
#

Looks like 95c0b1a59f3dc8f496a966e9f3e947b0cd9e81b8 doesn't leak too, testing with aad82f088b4d39f7996980f8f71bfc6e5dee5c52 now

dense karma
# lapis valley What even is that long string?

As Qjuh said it's a Git hash, which I use for referencing a specific version of the code. Though I've made my own script to load the packages from GitHub, because while you can install a npm package from a hash, you can't run any build scripts or similar with it, however they are required by djs to work

keen cave
#

You can install the dev releases from npm though. No idea why you need to install from git directly

dense karma
#

Because the dev releases are just "the" dev release, there's no version attached to it which makes things like debugging which commit (might) have caused it much harder

keen cave
#
dense karma
#

oh, well nevermind then
I only saw discord.js@dev some time ago and thought that's it