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:
CraftBukkit/Spigot 2014-04-25 23:46:46 +02:00
parent 8b9d2faa11
commit 05f3042755
2 changed files with 36 additions and 6 deletions

View file

@ -1,17 +1,18 @@
--- a/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();
public Channel channel;
public SocketAddress address;
+ // Spigot Start
+ public java.util.UUID spoofedUUID;
+ public com.mojang.authlib.properties.Property[] spoofedProfile;
+ public boolean preparing = true;
+ // Spigot End
@Nullable
private volatile PacketListener disconnectListener;
@Nullable
@@ -114,6 +118,7 @@
@@ -114,6 +119,7 @@
private volatile DisconnectionDetails delayedDisconnect;
@Nullable
BandwidthDebugMonitor bandwidthDebugMonitor;
@ -19,7 +20,17 @@
public Connection(PacketFlow 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) {
@@ -205,7 +211,7 @@
@@ -205,7 +215,7 @@
}
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener listener) {
@ -36,7 +47,15 @@
}
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()) {
@ -45,7 +64,7 @@
this.disconnectionDetails = disconnectionInfo;
}
@@ -537,7 +543,7 @@
@@ -537,7 +550,7 @@
}
public void configurePacketHandler(ChannelPipeline pipeline) {

View file

@ -43,3 +43,14 @@
Iterator<Connection> iterator = this.connections.iterator();
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();
}