BackSlot

BackSlot

3M Downloads

Doing server-side packet handling on networking thread which is not thread-safe

qouteall opened this issue ยท 2 comments

commented

The switch item packet is directly handled in the networking thread. However the packet handling process changes player inventory. So it's not thread-safe. Although it's not thread-safe, relevant bugs can occur very rarely so it usually gets unnoticed.

ServerPlayNetworking.registerGlobalReceiver(BackSlotServerPacket.SWITCH_PACKET, receiver);

https://github.com/Globox1997/BackSlot/blob/1.19/src/main/java/net/backslot/network/SwitchPacketReceiver.java#L42

The fix is simple, just handle the packet in server.execute(() -> {...})

I noticed this because someone reported that ImmPtl crashes with it iPortalTeam/ImmersivePortalsMod#1323

ImmPtl is just doing thread checking to help debugging. So this is not ImmPtl's issue.

commented

Fabric API's old networking API design is not good (it does not enforce the handling thread). It's part of the reason. Fabric API introduced the new object-based networking API which is easier to use and can avoid this thread safety issue.

commented

Thanks for the info qouteall. Fixed it :)