Discord Integration Forge

Discord Integration Forge

935k Downloads

[BUG] Massive ram spike to the point of server crashing

jpwanabe opened this issue · 11 comments

commented

What happened?

  • Suddenly the discord -> Minecraft messages stop and ram climbs with every message sent in discord until the server crashes

What should happen?

  • Not that

Steps to reproduce

  • Randomly happens.

Version

  • 1.12
  • 1.16

Platform

  • Forge
  • Spigot

Mod version:
dcintegration-forge-2.3.2-1.16.jar

Config file
-https://pastebin.com/k2XDcKpi
REMOVE YOUR BOT TOKEN BEFORE UPLOADING!!!

Crash report if available (use https://hastebin.com)
-Not a crash but some of the error
https://pastebin.com/TBu0qFK5

Additional info

This happens randomly. I've seen it happen on multiple versions but this was the first time I watched it happen in console. This plugin is the best I've seen for discord and Minecraft so I want to keep it.

commented
commented

I will look into this. Usually an ratelimit (which is what seems to happen here) should not use that much RAM.
For some reason it overuses this webhook.
Can you try if this bug also happens with webhook mode disabled?

commented

Interesting.
Will need to look at it on some public server...
Currently while changing whitelisting stuff, I got an bug which causes whitelisting to fail for no reason (no errors in log). Will investigate this even more as soon as I get the chance to do that

commented

So I've been running the plug-in without webhooks and it has still happens multiple times. It seems to be when a player is trying to whitelist themselves and is messing up the command. I think if you spam the bot with wrong commands over and over again it causes this. I've only been able to do it once myself since trying. And it only seems to work if the server already has five or more players on it.

commented

I may have an idea with the whitelisting. I have had players fail if their minecraft name had any discord formatting commands in it. With the old version or the new one. I understood why the /whitelist "mc name" would fail, but not so sure why !link # would. Maybe the bot response telling you your name?

commented

@ErdbeerbaerLP I've been experiencing a similar issue on my server using the Forge version on mc 1.16 where RAM usage climbs to the point that it crashes the server due to the GC having to work overtime (by the point Xmx is reached). Raising Xmx just increases the amount of time needed until this happens regardless of if the server is idle or has players, so it definitely seems like a memory leak. I am using the most current version of the mod for 1.16 as of this comment.

I haven't necessarily been able to directly link the issue to messages not sending to discord, though I took a heap dump of the server when it crashed and it is showing the rate limiter to be consuming the bulk of the server's RAM usage (~3.5 out of 4GB total allocated) to the point where it over-stresses the Garbage Collector, causing the crash. The pattern I have noticed is that it starts building up gradually over time, even when the server is idle, though I'll have to see if messages aren't getting through when the RAM usage starts to run high again. I'll attach a report I generated from the heap dump to give an idea of how many requests are getting backed up in memory in addition to a copy of my GC logs since it gives a good illustration of how the memory gradually increases over time.

If you're needing further information, I could send you snapshots and other reports of the heap dump if you specify which classes you care about seeing in the dump to keep the amount of processing minimal, or if that doesn't suffice, I can send a copy of the whole heap dump (Indexing the full dump took about 8GB of RAM allocated to eclipse MAT if we want to go that direction, though I still have my index files around if that helps.)

Let me know if there's anything else I can do to help. You've certainly got the most feature-rich discord mod for forge that is still maintained and it has all the features I'm needing for my server, though I may have to remove the mod until we can get this fixed up.

heapdump.20210929.122708.1227838.0001_Leak_Suspects.zip
verbosegc.20210928.225009.1227838.txt

commented

For context, I have been running the server on OpenJ9 when I generated these logs and the heap dump, though the issue occurs in a hotspot-based build of Java as well. I've tried just about every set of garbage collection tweaks as I can think of with multiple different algorithms on both hotspot and openj9 and the same behavior ultimately plays out for me.

commented

Note sure if this is connected to #283 in any way or if that issue is contributing to the build-up of requests in the rate limiter's memory, but I do experience extreme lag in the server as it approaches the crash point. In my case, the lag seems to be caused by the very frequent garbage collection as the memory fills up.

commented

An update: May have found a cause for the build-up of rate-limited requests. Apparently, this mod has been logging command block output to discord, even if the commands do not send anything to the in-game server chat. We have a command block circuit that's constantly running at spawn of my server, which might be the cause of the message build-up and extreme RAM usage. Is there some config option that sends all command block output to the server or is this a bug where it's picking up on everything a command block outputs regardless of if it's sent to the in-game chat or not? Found the config option that logs commands to discord. Will try disabling it to see if that solves my issue. If it does, I'll probably open up a feature request to have an option where the command logging config can have some way to exclude command blocks and only log commands sent by players.

commented

@ErdbeerbaerLP I have an update on this. Disabling command logging seems to prevent the memory leak from occurring. However, I do not know if the bug only occurs if the channel ID for command logging is for a channel that does not exist (had a nonexistent channel in my case) or if it also occurs with cases where the channel exists. May want to look into whether the issue can be re-created when the channel exists. Command block and data pack commands were getting logged by this mod while I was troubleshooting my server.

@jpwanabe you might want to try disabling command logging to see if that prevents the RAM spike for you.

commented

More info on this crash. If a player types the !link # command in the chat the bot is using the bot goes offline on discord almost 100% of the time. Then the ram starts to spike. And crash soon after.