#Memory leak in discord js
27 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - 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!
nesting event listeners, enabling unnecessary intents, making multiple event listeners for the same event
i just had a similar ish issue and it seems sweepers/ cache settings helped
They don’t help with memory leaks. They only help with memory usage reduction
.-. 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)
^, they won't help fixing this... xD
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
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)
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
Nope, that guide doesn't help me at all because the issue is not in my code xD
I was able to create a heap dump now using the heapdump package, I'll try creating another one once memory starts leaking again
How did you determine that to be the case?
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
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
Because it worked before I've updated djs, then it started leaking, and after I've changed back to 637e1a4ddb6d5810deb31c5b90400ca277218270 it stopped leaking
What even is that long string?
A commit hash
ahh
Looks like 95c0b1a59f3dc8f496a966e9f3e947b0cd9e81b8 doesn't leak too, testing with aad82f088b4d39f7996980f8f71bfc6e5dee5c52 now
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
You can install the dev releases from npm though. No idea why you need to install from git directly
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
There sure are. They contain the GitHub hash in their version identifier
https://www.npmjs.com/package/discord.js/v/14.14.2-dev.1700352622-ce0be392d for example is the release for the https://github.com/discordjs/discord.js/commit/ce0be392d818b13ba5a081811519b559202cdba8 commit, as visible in the commit hash
oh, well nevermind then
I only saw discord.js@dev some time ago and thought that's it