CavePVP-Stuff/cSpigot-master/spigot-server-Patches/0142-Pull-in-a-PaperSpigot-patch-to-avoid-blocking-netty.patch

54 lines
2.8 KiB
Diff
Raw Permalink Normal View History

2023-05-01 20:59:40 +02:00
From 63cb64b4b71712e3c54af86ce92c7c7c428b8769 Mon Sep 17 00:00:00 2001
From: Poweruser <poweruser.rs@hotmail.com>
Date: Sun, 12 Jun 2016 03:41:51 +0200
Subject: [PATCH] Pull in a PaperSpigot patch to avoid blocking netty
diff --git a/src/main/java/net/minecraft/server/ServerConnection.java b/src/main/java/net/minecraft/server/ServerConnection.java
index 981e22cc3..7afe17b43 100644
--- a/src/main/java/net/minecraft/server/ServerConnection.java
+++ b/src/main/java/net/minecraft/server/ServerConnection.java
@@ -25,6 +25,18 @@ public class ServerConnection {
private final List e = Collections.synchronizedList(new ArrayList());
private final List f = Collections.synchronizedList(new ArrayList());
+ // Paper start - prevent blocking on adding a new network manager while the server is ticking
+ protected final List<NetworkManager> pending = Collections.synchronizedList(new ArrayList<NetworkManager>());
+ private void addPending() {
+ synchronized (pending) {
+ synchronized (this.f) {
+ this.f.addAll(pending);
+ pending.clear();
+ }
+ }
+ }
+ // Paper end
+
public ServerConnection(MinecraftServer minecraftserver) {
this.d = minecraftserver;
this.a = true;
@@ -53,6 +65,7 @@ public class ServerConnection {
List list = this.f;
synchronized (this.f) {
+ addPending(); // Paper
// Spigot Start
// This prevents players from 'gaming' the server, and strategically relogging to increase their position in the tick order
if ( org.spigotmc.SpigotConfig.playerShuffle > 0 && MinecraftServer.currentTick % org.spigotmc.SpigotConfig.playerShuffle == 0 )
diff --git a/src/main/java/net/minecraft/server/ServerConnectionChannel.java b/src/main/java/net/minecraft/server/ServerConnectionChannel.java
index d7d93a07c..9058aab5a 100644
--- a/src/main/java/net/minecraft/server/ServerConnectionChannel.java
+++ b/src/main/java/net/minecraft/server/ServerConnectionChannel.java
@@ -30,7 +30,7 @@ class ServerConnectionChannel extends ChannelInitializer {
channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30)).addLast("legacy_query", new LegacyPingHandler(this.a)).addLast("splitter", new PacketSplitter()).addLast("decoder", new PacketDecoder(NetworkManager.h)).addLast("prepender", new PacketPrepender()).addLast("encoder", new PacketEncoder(NetworkManager.h));
NetworkManager networkmanager = new NetworkManager(false);
- ServerConnection.a(this.a).add(networkmanager);
+ this.a.pending.add(networkmanager); // Paper
channel.pipeline().addLast("packet_handler", networkmanager);
networkmanager.a((PacketListener) (new HandshakeListener(ServerConnection.b(this.a), networkmanager)));
}
--
2.13.3