retrooper / packetevents

PacketEvents is emerging as a strong contender in the realm of Minecraft packet processing libraries. Designed to simplify packet manipulation while delivering high performance, this powerful tool aims to demystify the complexities of projects utilizing packets.
GNU General Public License v3.0
513 stars 148 forks source link

PacketEvents 2.0 memory leak #395

Closed MWHunter closed 2 years ago

MWHunter commented 2 years ago

Describe the bug Occasionally, when a player disconnects, they will remain in the player hashmap

Software brand Pufferfish 1.18.2

Plugins Plugins (9): Essentials, LuckPerms, packetevents*, ProtocolLib, spark, TAB, ViaBackwards, ViaRewind, ViaVersion

How To Reproduce Steps to reproduce the behavior: Example: Use lambdaattack to rapidly join users, and cancel the attack while users are joining. Some players will be stuck in the hashmap.

Expected behavior No memory leaks

Screenshots [23:45:40 INFO]: [packetevents] [STDOUT] Users size (pre-add): 4

Additional context This also affects GrimAC,, UserDisconnectEvent is not being called correctly

MWHunter commented 2 years ago

seems to be called by relying on the bukkit event to remove users, no other places are calling remove

MWHunter commented 2 years ago

I'll ask for forgiveness rather than permission, but after spamming my local server with bots, this commit seems to have fixed it: https://github.com/retrooper/packetevents/commit/a670961b991d050c2048e1634e61f7b941271f49

Will leave this issue open so you see it though

MWHunter commented 2 years ago

nevermind, it is still somehow leaking players, although this commit is better

MWHunter commented 2 years ago

nevermind, gradle caches were screwing with me. After spamming start and stop on lambdaattack, with thousands of bots, I have found no leak.

MWHunter commented 2 years ago

Another memory leak was found with https://github.com/retrooper/packetevents/commit/0f061764e6ce2b32ba8f2b32ea58c028cfa9e70b

I will report back if there is still another memory leak.

retrooper commented 2 years ago

The handleDisconnection is already called on channel close in our encoder.

retrooper commented 2 years ago

I'll see what debugging I can do. How'd you get bots?

MWHunter commented 2 years ago

I used lambdaattack. handleDisconnection is not being called. The two commits I have linked have fixed this, but there's likely something wrong with your handleDisconnection code if it isn't being called correctly

retrooper commented 2 years ago

Remove the call in the encoder.

MWHunter commented 2 years ago

Fixed by https://github.com/retrooper/packetevents/commit/96d8fc6d21f9d29d67f68ad3e9efb14e52d24717 https://github.com/retrooper/packetevents/commit/1868cee073b68bbbccdc6d699c3305ae00e3961e https://github.com/retrooper/packetevents/commit/351742e88e8f0ba878b7302c84ece4e15407183d https://github.com/retrooper/packetevents/commit/bd67caaeb8cb304f7851f8f43cb799485e7eddad and https://github.com/retrooper/packetevents/commit/16f9eb32c9fddb911b296c33de28ac229be88eaf