When playing on specific Minecraft servers, I noticed some lag spikes. I've checked the logs and found out what it was caused by:
>> [16:41:10] [Render thread/ERROR]: Error executing task on Client >> y: Main thread packet handler >> at xh.a(SourceFile:33) ~[1.20.4.jar:?] >> at bir.d(SourceFile:156) ~[1.20.4.jar:?] >> at biv.d(SourceFile:23) ~[1.20.4.jar:?] >> at bir.x(SourceFile:130) ~[1.20.4.jar:?] >> at bir.bu(SourceFile:115) ~[1.20.4.jar:?] >> at evi.d(SourceFile:1283) ~[1.20.4.jar:?] >> at evi.f(SourceFile:888) ~[1.20.4.jar:?] >> at net.minecraft.client.main.Main.main(SourceFile:265) ~[1.20.4.jar:?] >> Caused by: java.lang.IllegalStateException: Player is either on another team or not on any team. Cannot remove from team 'Z/Osi/650500'. >> at emx.b(SourceFile:307) ~[1.20.4.jar:?] >> at fnt.a(SourceFile:2029) ~[1.20.4.jar:?] >> at ack.a(SourceFile:129) ~[1.20.4.jar:?] >> at ack.a(SourceFile:14) ~[1.20.4.jar:?] >> at xh.a(SourceFile:24) ~[1.20.4.jar:?] >> ... 7 more
I know, that issues with modificated Minecraft clients are not accepted, but I wrote a Fabric mod with possible workaround myself, and it actually worked, lag spikes caused by this exact exception were gone (mod source code).
Steps to reproduce:
0. Optionally, run software which can draw frametime graph overlay (for example, MSI Afterburner with RivaTunerStatisticsServer)
1. Launch Minecraft with console enabled and switch to windowed mode to keep an eye on debug info
2. Join server "mclucky.net" (Russian server)
3. Solve captcha
4. Register: /reg <password>
5. Go to the blue "MURDERMYSTERY" portal
6. Run around for 1-3 minutes and you will see lag spikes on the frametime graph and new exceptions periodically printed out to console
Video: link (necessarily download it before watching)
On the right bottom corner I placed MSI Afterburner's detachable monitoring window, showing and updating CPU usage graph every 150ms (more frequently than Windows' task manager). Please, take a closer look at the frametime graph rendering on the top of the Minecraft window. It perfectly corresponds with moments where new exceptions messages printed out to the console (left top side of video). All the frametime spikes you would see on the footage's frametime graph were perfectly visible with my naked eyes during recording. I'm sorry if my video is not a high quality one, but I think it should be enough to demonstrate the bug.
Greymagic27 asked me to show what would task manager display, but actually it's not even noticeable if judging only by CPU utilization. The bug (lag) affects only in-game render thread.
Testing was performed on laptop ASUS TUF Gaming A15 FA506IH:
CPU: Ryzen 5 4600H
GPU: NVIDIA GeForce GTX 1650 (mobile) + Radeon (integrated)
RAM: 1x16GB DDR4-3200
Display: 1920x1080, 144hz - makes lags more noticeable
OS: Microsoft Windows 11 23H2, build 22631.3296
I've done another research and found out that something big in codebase was changed or rewritten. I've tested all latest Minecraft releases and concluded that lags were started to appear in version 1.20.3. Even exception messages are looking differently.
1.20.2 (no lags):
[20:06:53] [Render thread/ERROR]: Error executing task on Client java.lang.IllegalStateException: Player is either on another team or not on any team. Cannot remove from team 'collideRule_-972'. at eim.b(SourceFile:213) ~[1.20.2.jar:?] at fiy.a(SourceFile:1967) ~[1.20.2.jar:?] at aaf.a(SourceFile:129) ~[1.20.2.jar:?] at aaf.a(SourceFile:14) ~[1.20.2.jar:?] at vf.a(SourceFile:23) ~[1.20.2.jar:?] at bfo.d(SourceFile:156) ~[1.20.2.jar:?] at bfs.d(SourceFile:23) ~[1.20.2.jar:?] at bfo.x(SourceFile:130) ~[1.20.2.jar:?] at bfo.bp(SourceFile:115) ~[1.20.2.jar:?] at eqv.d(SourceFile:1231) ~[1.20.2.jar:?] at eqv.f(SourceFile:856) ~[1.20.2.jar:?] at net.minecraft.client.main.Main.main(SourceFile:253) ~[1.20.2.jar:?]
1.20.3 (lags):
[20:10:00] [Render thread/ERROR]: Error executing task on Client y: Main thread packet handler at xh.a(SourceFile:33) ~[1.20.3.jar:?] at bir.d(SourceFile:156) ~[1.20.3.jar:?] at biv.d(SourceFile:23) ~[1.20.3.jar:?] at bir.x(SourceFile:130) ~[1.20.3.jar:?] at bir.bu(SourceFile:115) ~[1.20.3.jar:?] at evi.d(SourceFile:1283) ~[1.20.3.jar:?] at evi.f(SourceFile:888) ~[1.20.3.jar:?] at net.minecraft.client.main.Main.main(SourceFile:265) ~[1.20.3.jar:?] Caused by: java.lang.IllegalStateException: Player is either on another team or not on any team. Cannot remove from team 'collideRule_-972'. at emx.b(SourceFile:307) ~[1.20.3.jar:?] at fnt.a(SourceFile:2029) ~[1.20.3.jar:?] at ack.a(SourceFile:129) ~[1.20.3.jar:?] at ack.a(SourceFile:14) ~[1.20.3.jar:?] at xh.a(SourceFile:24) ~[1.20.3.jar:?] ... 7 more
Maybe the solution (Fabric mod) for this I made isn't perfect, but anyway the exception shouldn't be thrown on render thread and cause visual lags.