Closed qouteall closed 1 year ago
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.
Thanks for the info qouteall. Fixed it :)
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.
https://github.com/Globox1997/BackSlot/blob/f6b32510e2eccc463190b844c291153e83b80602/src/main/java/net/backslot/network/BackSlotServerPacket.java#L13
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 https://github.com/iPortalTeam/ImmersivePortalsMod/issues/1323
ImmPtl is just doing thread checking to help debugging. So this is not ImmPtl's issue.