Tnze / go-mc

Collection of Go libraries for Minecraft
https://go-mc.github.io/tutorial/
MIT License
848 stars 114 forks source link

Packet reading hangs and goes into infinite loop trying to read a packet #254

Closed maxsupermanhd closed 1 year ago

maxsupermanhd commented 1 year ago

Describe the bug After updating to 1.19.4 (master) from 1.19.2 in certain condition bot hangs and infinitely reads same packet.

I have a discord bridge that has tab rendering: https://github.com/maxsupermanhd/BlockBridge/tree/v762.0.0

Sometimes when I request a tab image from discord (/tab) it draws the tab perfectly fine but after that consumes 100% of one core and does not receive nor parse new packets and does not disconnect even if underlying connection is being killed by keepalive killer or closed by the server.

Additional context It is not a race or threading issue, tested with -race and same result

Tnze commented 1 year ago

Do you know which loop is infinite? VarInt?

Tnze commented 1 year ago

There are some guides using gdb to debug infinity loops:

gdb a.out
info threads
thread thread_id
info frame
maxsupermanhd commented 1 year ago

Yes, I know that HandleGame never exits, when adding debug logging it is being stuck at reading same packet again and again and again. It is trying to read chat.Message (the tab menu).

maxsupermanhd commented 1 year ago

I sent more debugging information in Discord. It seems like it actually reads from connection same packet and underlying conn and fd thinks it is connected (it is not)

maxsupermanhd commented 1 year ago

Ok, some very valuable information in my opinion: image When connection pull fails it fails without setting an error and it causes it to reuse same packet over and over again because it is never updated in the first place @Tnze Not funny!