Fix rare crash from HandshakeHandler in 5.27.0+

The existing Forge logic can concurrently modify sentMessages from two threads,
since handleIndexedMessage runs on the Netty thread, while tickServer is on the
server thread. Ticking the handler faster made the race condition significantly
more likely to manifest.
This commit is contained in:
embeddedt 2026-04-14 22:20:53 -04:00
parent 327c3cd9ff
commit c2f585da95
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -8,8 +8,11 @@ import net.minecraftforge.network.NetworkRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Collections;
import java.util.List;
@Mixin(value = HandshakeHandler.class, remap = false)
@ -23,6 +26,16 @@ public class HandshakeHandlerMixin {
@Shadow
private List<Integer> sentMessages;
/**
* @author embeddedt
* @reason we must synchronize sentMessages because it is modified from both the Netty thread and the
* server thread
*/
@Inject(method = "<init>", at = @At("RETURN"))
private void synchronizeSentMessages(CallbackInfo ci) {
this.sentMessages = Collections.synchronizedList(this.sentMessages);
}
/**
* @author embeddedt
* @reason Forge only sends one login payload per tick. It takes many seconds to send all the payloads at this rate.