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:
parent
327c3cd9ff
commit
c2f585da95
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user