mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
64 lines
2.8 KiB
Diff
64 lines
2.8 KiB
Diff
From b23cad30d0407c9247cf6327724aa31bc737d92b Mon Sep 17 00:00:00 2001
|
|
From: Jonas Konrad <me@yawk.at>
|
|
Date: Fri, 25 Apr 2014 23:46:46 +0200
|
|
Subject: [PATCH] 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.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
|
|
index b62cc5a..006b172 100644
|
|
--- a/src/main/java/net/minecraft/server/NetworkManager.java
|
|
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
|
|
@@ -68,6 +68,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {
|
|
public SocketAddress l;
|
|
public java.util.UUID spoofedUUID;
|
|
public com.mojang.authlib.properties.Property[] spoofedProfile;
|
|
+ public boolean preparing = true;
|
|
// Spigot End
|
|
private PacketListener m;
|
|
private IChatBaseComponent n;
|
|
@@ -82,6 +83,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {
|
|
super.channelActive(channelhandlercontext);
|
|
this.k = channelhandlercontext.channel();
|
|
this.l = this.k.remoteAddress();
|
|
+ // Spigot Start
|
|
+ this.preparing = false;
|
|
+ // Spigot End
|
|
|
|
try {
|
|
this.a(EnumProtocol.HANDSHAKING);
|
|
@@ -235,6 +239,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {
|
|
}
|
|
|
|
public void close(IChatBaseComponent ichatbasecomponent) {
|
|
+ // Spigot Start
|
|
+ this.preparing = false;
|
|
+ // Spigot End
|
|
if (this.k.isOpen()) {
|
|
this.k.close(); // We can't wait as this may be called from an event loop.
|
|
this.n = ichatbasecomponent;
|
|
diff --git a/src/main/java/net/minecraft/server/ServerConnection.java b/src/main/java/net/minecraft/server/ServerConnection.java
|
|
index 931ab66..2708d64 100644
|
|
--- a/src/main/java/net/minecraft/server/ServerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/ServerConnection.java
|
|
@@ -137,6 +137,10 @@ public class ServerConnection {
|
|
|
|
if (!networkmanager.h()) {
|
|
if (!networkmanager.g()) {
|
|
+ // Spigot Start
|
|
+ // Fix a race condition where a NetworkManager could be unregistered just before connection.
|
|
+ if (networkmanager.preparing) continue;
|
|
+ // Spigot End
|
|
iterator.remove();
|
|
networkmanager.l();
|
|
} else {
|
|
--
|
|
2.1.0
|
|
|