mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Fix race condition that could kill connections before they were initiated
Because NetworkManagers are registered before they get their channel in channelActive, the ServerConnection would remove them sometimes because it thought they were disconnected. This commit fixes this by introducing a 'preparing' variable that is true while the NetworkManager is not initialized. The ServerConnection does not remove NetworkManagers with this flag. By: Jonas Konrad <me@yawk.at>
This commit is contained in:
parent
8b9d2faa11
commit
05f3042755
2 changed files with 36 additions and 6 deletions
|
@ -1,17 +1,18 @@
|
||||||
--- a/net/minecraft/network/Connection.java
|
--- a/net/minecraft/network/Connection.java
|
||||||
+++ b/net/minecraft/network/Connection.java
|
+++ b/net/minecraft/network/Connection.java
|
||||||
@@ -96,6 +96,10 @@
|
@@ -96,6 +96,11 @@
|
||||||
private final Queue<Consumer<Connection>> pendingActions = Queues.newConcurrentLinkedQueue();
|
private final Queue<Consumer<Connection>> pendingActions = Queues.newConcurrentLinkedQueue();
|
||||||
public Channel channel;
|
public Channel channel;
|
||||||
public SocketAddress address;
|
public SocketAddress address;
|
||||||
+ // Spigot Start
|
+ // Spigot Start
|
||||||
+ public java.util.UUID spoofedUUID;
|
+ public java.util.UUID spoofedUUID;
|
||||||
+ public com.mojang.authlib.properties.Property[] spoofedProfile;
|
+ public com.mojang.authlib.properties.Property[] spoofedProfile;
|
||||||
|
+ public boolean preparing = true;
|
||||||
+ // Spigot End
|
+ // Spigot End
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile PacketListener disconnectListener;
|
private volatile PacketListener disconnectListener;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -114,6 +118,7 @@
|
@@ -114,6 +119,7 @@
|
||||||
private volatile DisconnectionDetails delayedDisconnect;
|
private volatile DisconnectionDetails delayedDisconnect;
|
||||||
@Nullable
|
@Nullable
|
||||||
BandwidthDebugMonitor bandwidthDebugMonitor;
|
BandwidthDebugMonitor bandwidthDebugMonitor;
|
||||||
|
@ -19,7 +20,17 @@
|
||||||
|
|
||||||
public Connection(PacketFlow side) {
|
public Connection(PacketFlow side) {
|
||||||
this.receiving = side;
|
this.receiving = side;
|
||||||
@@ -176,6 +181,7 @@
|
@@ -123,6 +129,9 @@
|
||||||
|
super.channelActive(channelhandlercontext);
|
||||||
|
this.channel = channelhandlercontext.channel();
|
||||||
|
this.address = this.channel.remoteAddress();
|
||||||
|
+ // Spigot Start
|
||||||
|
+ this.preparing = false;
|
||||||
|
+ // Spigot End
|
||||||
|
if (this.delayedDisconnect != null) {
|
||||||
|
this.disconnect(this.delayedDisconnect);
|
||||||
|
}
|
||||||
|
@@ -176,6 +185,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +38,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet<?> packet) {
|
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet<?> packet) {
|
||||||
@@ -205,7 +211,7 @@
|
@@ -205,7 +215,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener listener) {
|
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener listener) {
|
||||||
|
@ -36,7 +47,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateListener(ProtocolInfo<?> state, PacketListener listener) {
|
private void validateListener(ProtocolInfo<?> state, PacketListener listener) {
|
||||||
@@ -469,7 +475,7 @@
|
@@ -464,12 +474,15 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect(DisconnectionDetails disconnectionInfo) {
|
||||||
|
+ // Spigot Start
|
||||||
|
+ this.preparing = false;
|
||||||
|
+ // Spigot End
|
||||||
|
if (this.channel == null) {
|
||||||
|
this.delayedDisconnect = disconnectionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isConnected()) {
|
if (this.isConnected()) {
|
||||||
|
@ -45,7 +64,7 @@
|
||||||
this.disconnectionDetails = disconnectionInfo;
|
this.disconnectionDetails = disconnectionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,7 +543,7 @@
|
@@ -537,7 +550,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void configurePacketHandler(ChannelPipeline pipeline) {
|
public void configurePacketHandler(ChannelPipeline pipeline) {
|
||||||
|
|
|
@ -43,3 +43,14 @@
|
||||||
Iterator<Connection> iterator = this.connections.iterator();
|
Iterator<Connection> iterator = this.connections.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
@@ -176,6 +193,10 @@
|
||||||
|
networkmanager.setReadOnly();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
+ // Spigot Start
|
||||||
|
+ // Fix a race condition where a NetworkManager could be unregistered just before connection.
|
||||||
|
+ if (networkmanager.preparing) continue;
|
||||||
|
+ // Spigot End
|
||||||
|
iterator.remove();
|
||||||
|
networkmanager.handleDisconnection();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue