BUG: "Tried to read NBT tag that was too big" on joining a server
noncom opened this issue ยท 3 comments
Minecraft Version
1.20.1
Forge Version
47.2.6
Lightman's Currency Version
lightmanscurrency-1.20.1-2.1.2.4b.jar
Environment Type
Minecraft Client when joining the multiplayer server with an existing world which worked fine all the time before.
Other relevant Mods
Any mod that adds an extensive amount of NBT to the items being traded, for example Mine and Slash.
The modpack where this issue was first caught: Craft to Exile 2.
The mod Packet Fixer (PacketFixer-forge-1.2.1-1.20.1.jar) fixes the issue!
But we're still filing it here since we believe that Lightman's Currency can do better!
Describe the bug
Playing on a server all players at once suddenly stop being able to connect, seeing:
With the log:
latest_2.log
There is no exception in the log and no crash, but you can see the lines:
{
"f_132075_": "translation{key='disconnect.genericReason', args=[Internal Exception: java.lang.RuntimeException: Tried to read NBT tag that was too big; tried to allocate: 2097154bytes where max allowed: 2097152]}"
}
To Reproduce
- Create a ton of trade offers on a server
- Have the items having a ton of NBT, for example by submitting a lot of Mine and Slash trades.
Screenshots/Logs/Crash Reports
Had to trace this with a debugger, and:
and
Players were known to create an extrensive amount of trade offers with Mine and Slash items, which have a lot of NBT on the items.
This bug prevents using Lightman's Currency on servers with a highly customized gameplay where NBT data plays a big role.
Here's also the dump of that particular NBT that is causing trouble to us:
lightmans-currency-nbt-dump..txt
Possible Solution
Maybe split the package?
The NbtAccounter
which generates the exception is re-created for each new packet, so it forgets what it read before.
So keeping the packets under 2 megabytes should work..
Packet-Fixer way is another approach, of course, but that's like making some assumptions outside of this mod.
According to your debug images (at least the first one, the second link doesn't work, and the nbt dump file is illegible even to NBT Explorer), the packet causing this is actually the bank account sync packet, not the trader sync packet. It appears that by some oversight, the sync packet for the bank accounts didn't use the readUnlimitedNbt function, and it also attempts to sync them all at once instead of one at a time like the traders do (which I thought was fine, as bank accounts contain far less data).
Apparently you managed to get enough players on the server to create a ludicrous amount of bank accounts, but either way I'll get on optimizing those packets for ya, and while I'm at it I'll make sure all of my other packets use the readUnlimitedNbt option so that other issues like this don't appear.
Awesome! Thank you a lot!
Also for the explanation, it's a curious fact ๐
And sorry, idk about the logs or images, for me everything in the OP shows and downloads properly. I used the default github issue creation editor and just pasted all the stuff there. Hmm so maybe it's some github issue, not sure about this one.
The images 2 and 3 show a stop on the breakpoint which is set up on the line that generates the exception, and the stack trace to this mod + the beginning of the culprit packet are visible in the debugger window.
As for the NBT file -- yeah, it might be not a proper NBT -- I got it just by dumping the bytes from the buffer into a string during a stop on the debug point. So it well might have resulted in an incorrect/corrupted NBT. I didn't find any other way to dump this data though.
I am not very familiar with Minecraft stuff and mod development, so I had no idea what I was doing ๐. It's partially readable with a text editor though, and shows some json-like data, so I was hoping it was at least somewhat informative.
But it's cool that you have managed to pinpoint and fix the issue nevertheless! ๐
This is a great mod, especially on a server with a highly customized gameplay with a lot of cool items to trade.
We're very happy we can enjoy this even more from now on!