3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 11:00:06 +01:00

Remove deadlock risk in firing async events

The PluginManager incorrectly used synchronization on firing any event
that was marked as synchronous.

This synchronized did not even protect any concurrency risk as
handlers were already thread safe in terms of mutations during event
dispatch.

The way it was used, has commonly led to deadlocks on the server,
which results in a hard crash.

This change removes the synchronize and adds some protection around enable/disable
Dieser Commit ist enthalten in:
Aikar 2018-09-09 01:04:29 -04:00
Ursprung 4e30b91d4e
Commit 5228a4f24c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 401ADFC9891FAAFE
6 geänderte Dateien mit 120 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
From b036cb38ebab110e948775363f38ffb16c149199 Mon Sep 17 00:00:00 2001
From 83e63475155067753ed63d35b7e5998c75feff72 Mon Sep 17 00:00:00 2001
From: cswhite2000 <18whitechristop@gmail.com>
Date: Tue, 21 Aug 2018 19:39:46 -0700
Subject: [PATCH] isChunkGenerated API
@ -6,7 +6,7 @@ Subject: [PATCH] isChunkGenerated API
Resolves #1329
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
index 7e1ee875..9457832b 100644
index 7e1ee875e..9457832bc 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -9,6 +9,7 @@ import org.bukkit.util.NumberConversions;
@ -34,7 +34,7 @@ index 7e1ee875..9457832b 100644
/**
* Sets the position of this Location and returns itself
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index a6facc4b..d5058634 100644
index a6facc4b0..d50586349 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -210,6 +210,26 @@ public interface World extends PluginMessageRecipient, Metadatable {

Datei anzeigen

@ -1,11 +1,11 @@
From a802db6737065697d3668b53a32d9eb5265fdab5 Mon Sep 17 00:00:00 2001
From 3dfdb2062b0760e342784a09056d39c3266df738 Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
Date: Thu, 23 Aug 2018 16:14:25 +0800
Subject: [PATCH] Add source block to BlockPhysicsEvent
diff --git a/src/main/java/org/bukkit/event/block/BlockPhysicsEvent.java b/src/main/java/org/bukkit/event/block/BlockPhysicsEvent.java
index 01a545b4..d17e05ac 100644
index 01a545b42..57568cd02 100644
--- a/src/main/java/org/bukkit/event/block/BlockPhysicsEvent.java
+++ b/src/main/java/org/bukkit/event/block/BlockPhysicsEvent.java
@@ -12,6 +12,39 @@ public class BlockPhysicsEvent extends BlockEvent implements Cancellable {
@ -57,5 +57,5 @@ index 01a545b4..d17e05ac 100644
/**
--
2.18.0.windows.1
2.18.0

Datei anzeigen

@ -0,0 +1,83 @@
From cc0de4b8d6d4373fada1806dc617c7dc71160094 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 9 Sep 2018 00:32:05 -0400
Subject: [PATCH] Remove deadlock risk in firing async events
The PluginManager incorrectly used synchronization on firing any event
that was marked as synchronous.
This synchronized did not even protect any concurrency risk as
handlers were already thread safe in terms of mutations during event
dispatch.
The way it was used, has commonly led to deadlocks on the server,
which results in a hard crash.
This change removes the synchronize and adds some protection around enable/disable
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index cb2b0b9cb..a7dd902fb 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -385,7 +385,7 @@ public final class SimplePluginManager implements PluginManager {
* @param plugin Plugin to check
* @return true if the plugin is enabled, otherwise false
*/
- public boolean isPluginEnabled(Plugin plugin) {
+ public synchronized boolean isPluginEnabled(Plugin plugin) { // Paper - synchronize
if ((plugin != null) && (plugins.contains(plugin))) {
return plugin.isEnabled();
} else {
@@ -393,7 +393,7 @@ public final class SimplePluginManager implements PluginManager {
}
}
- public void enablePlugin(final Plugin plugin) {
+ public synchronized void enablePlugin(final Plugin plugin) { // Paper - synchronize
if (!plugin.isEnabled()) {
List<Command> pluginCommands = PluginCommandYamlParser.parse(plugin);
@@ -430,7 +430,7 @@ public final class SimplePluginManager implements PluginManager {
disablePlugin(plugin, false);
}
- public void disablePlugin(final Plugin plugin, boolean closeClassloader) {
+ public synchronized void disablePlugin(final Plugin plugin, boolean closeClassloader) { // Paper - synchronize
// Paper end - close Classloader on disable
if (plugin.isEnabled()) {
try {
@@ -490,6 +490,7 @@ public final class SimplePluginManager implements PluginManager {
defaultPerms.get(false).clear();
}
}
+ private void fireEvent(Event event) { callEvent(event); } // Paper - support old method incase plugin uses reflection
/**
* Calls an event with the given details.
@@ -499,22 +500,7 @@ public final class SimplePluginManager implements PluginManager {
* @param event Event details
*/
public void callEvent(Event event) {
- if (event.isAsynchronous()) {
- if (Thread.holdsLock(this)) {
- throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code.");
- }
- if (server.isPrimaryThread()) {
- throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from primary server thread.");
- }
- fireEvent(event);
- } else {
- synchronized (this) {
- fireEvent(event);
- }
- }
- }
-
- private void fireEvent(Event event) {
+ // Paper - replace callEvent by merging to below method
HandlerList handlers = event.getHandlers();
RegisteredListener[] listeners = handlers.getRegisteredListeners();
--
2.18.0

Datei anzeigen

@ -1,11 +1,11 @@
From f0b71b83e108ec6fcb256dbc1fcc79ee86edd311 Mon Sep 17 00:00:00 2001
From cc816d3a76029cb78e56a85a0d040a2789f7a91e Mon Sep 17 00:00:00 2001
From: stonar96 <minecraft.stonar96@gmail.com>
Date: Thu, 21 Sep 2017 00:38:47 +0200
Subject: [PATCH] Anti-Xray
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 646620d0c..4d30cdbc8 100644
index 646620d0c2..4d30cdbc8b 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -1,7 +1,10 @@
@ -49,7 +49,7 @@ index 646620d0c..4d30cdbc8 100644
}
diff --git a/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockController.java b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockController.java
new file mode 100644
index 000000000..6833cfad2
index 0000000000..6833cfad25
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockController.java
@@ -0,0 +1,36 @@
@ -91,7 +91,7 @@ index 000000000..6833cfad2
+}
diff --git a/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java
new file mode 100644
index 000000000..2dc0655a9
index 0000000000..2dc0655a93
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java
@@ -0,0 +1,640 @@
@ -737,7 +737,7 @@ index 000000000..2dc0655a9
+}
diff --git a/src/main/java/com/destroystokyo/paper/antixray/DataBitsReader.java b/src/main/java/com/destroystokyo/paper/antixray/DataBitsReader.java
new file mode 100644
index 000000000..92399318c
index 0000000000..92399318cd
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/antixray/DataBitsReader.java
@@ -0,0 +1,56 @@
@ -799,7 +799,7 @@ index 000000000..92399318c
+}
diff --git a/src/main/java/com/destroystokyo/paper/antixray/DataBitsWriter.java b/src/main/java/com/destroystokyo/paper/antixray/DataBitsWriter.java
new file mode 100644
index 000000000..aca0b9d71
index 0000000000..aca0b9d719
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/antixray/DataBitsWriter.java
@@ -0,0 +1,84 @@
@ -889,7 +889,7 @@ index 000000000..aca0b9d71
+}
diff --git a/src/main/java/com/destroystokyo/paper/antixray/PacketPlayOutMapChunkInfo.java b/src/main/java/com/destroystokyo/paper/antixray/PacketPlayOutMapChunkInfo.java
new file mode 100644
index 000000000..0bd269a07
index 0000000000..0bd269a079
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/antixray/PacketPlayOutMapChunkInfo.java
@@ -0,0 +1,80 @@
@ -975,7 +975,7 @@ index 000000000..0bd269a07
+}
diff --git a/src/main/java/com/destroystokyo/paper/antixray/PacketPlayOutMapChunkInfoAntiXray.java b/src/main/java/com/destroystokyo/paper/antixray/PacketPlayOutMapChunkInfoAntiXray.java
new file mode 100644
index 000000000..8ea2beb59
index 0000000000..8ea2beb597
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/antixray/PacketPlayOutMapChunkInfoAntiXray.java
@@ -0,0 +1,28 @@
@ -1008,7 +1008,7 @@ index 000000000..8ea2beb59
+ }
+}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 27a36b2b0..cb33cf902 100644
index 663a41e9e7..0226b96f30 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -158,7 +158,7 @@ public class Chunk {
@ -1039,7 +1039,7 @@ index 27a36b2b0..cb33cf902 100644
this.initLighting();
}
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
index 14f88e91d..bcce5e8b7 100644
index 14f88e91db..bcce5e8b7e 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -416,7 +416,7 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
@ -1052,7 +1052,7 @@ index 14f88e91d..bcce5e8b7 100644
NibbleArray nibblearray = new NibbleArray(nbttagcompound1.getByteArray("Data"));
NibbleArray nibblearray1 = nbttagcompound1.hasKeyOfType("Add", 7) ? new NibbleArray(nbttagcompound1.getByteArray("Add")) : null;
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
index afdc4a779..aae227fdb 100644
index afdc4a779a..aae227fdb0 100644
--- a/src/main/java/net/minecraft/server/ChunkSection.java
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
@@ -9,9 +9,15 @@ public class ChunkSection {
@ -1092,7 +1092,7 @@ index afdc4a779..aae227fdb 100644
int xx = i & 15;
int yy = (i >> 8) & 15;
diff --git a/src/main/java/net/minecraft/server/DataBits.java b/src/main/java/net/minecraft/server/DataBits.java
index fa0fd8a9c..401dc7cdc 100644
index fa0fd8a9c8..401dc7cdc5 100644
--- a/src/main/java/net/minecraft/server/DataBits.java
+++ b/src/main/java/net/minecraft/server/DataBits.java
@@ -51,6 +51,7 @@ public class DataBits {
@ -1104,7 +1104,7 @@ index fa0fd8a9c..401dc7cdc 100644
return this.a;
}
diff --git a/src/main/java/net/minecraft/server/DataPalette.java b/src/main/java/net/minecraft/server/DataPalette.java
index 5765b2588..d522611ec 100644
index 5765b25888..d522611ecb 100644
--- a/src/main/java/net/minecraft/server/DataPalette.java
+++ b/src/main/java/net/minecraft/server/DataPalette.java
@@ -4,8 +4,10 @@ import javax.annotation.Nullable;
@ -1119,7 +1119,7 @@ index 5765b2588..d522611ec 100644
IBlockData a(int i);
diff --git a/src/main/java/net/minecraft/server/DataPaletteBlock.java b/src/main/java/net/minecraft/server/DataPaletteBlock.java
index 2cb462b8e..67784b4a6 100644
index 2cb462b8e3..67784b4a67 100644
--- a/src/main/java/net/minecraft/server/DataPaletteBlock.java
+++ b/src/main/java/net/minecraft/server/DataPaletteBlock.java
@@ -2,22 +2,55 @@ package net.minecraft.server;
@ -1227,7 +1227,7 @@ index 2cb462b8e..67784b4a6 100644
}
diff --git a/src/main/java/net/minecraft/server/EntityFallingBlock.java b/src/main/java/net/minecraft/server/EntityFallingBlock.java
index d0b67d8fd..eeaa625d2 100644
index d0b67d8fd6..eeaa625d2f 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
@@ -74,6 +74,7 @@ public class EntityFallingBlock extends Entity {
@ -1247,7 +1247,7 @@ index d0b67d8fd..eeaa625d2 100644
if (block instanceof BlockFalling) {
((BlockFalling) block).a(this.world, blockposition, this.block, iblockdata);
diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java
index e148901e5..61fbdeb6a 100644
index e148901e53..61fbdeb6ac 100644
--- a/src/main/java/net/minecraft/server/Explosion.java
+++ b/src/main/java/net/minecraft/server/Explosion.java
@@ -228,6 +228,7 @@ public class Explosion {
@ -1259,7 +1259,7 @@ index e148901e5..61fbdeb6a 100644
if (flag) {
double d0 = (double) ((float) blockposition.getX() + this.world.random.nextFloat());
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
index d583cced6..2eddb68d7 100644
index d583cced66..2eddb68d7b 100644
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
@@ -62,7 +62,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
@ -1358,7 +1358,7 @@ index d583cced6..2eddb68d7 100644
public QueuedPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>>... agenericfuturelistener) {
this.a = packet;
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
index c1273e988..d71734df8 100644
index c1273e988e..d71734df81 100644
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
@@ -33,6 +33,7 @@ public class PacketDataSerializer extends ByteBuf {
@ -1370,7 +1370,7 @@ index c1273e988..d71734df8 100644
for (int j = 1; j < 5; ++j) {
if ((i & -1 << j * 7) == 0) {
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
index d16669bcc..306a6b7cd 100644
index d16669bcc3..306a6b7cd3 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
@@ -8,6 +8,10 @@ import java.util.Iterator;
@ -1463,7 +1463,7 @@ index d16669bcc..306a6b7cd 100644
if (flag) {
packetdataserializer.writeBytes(chunksection.getSkyLightArray().asBytes());
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
index 48a008e0a..395386f29 100644
index 48a008e0a7..395386f295 100644
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -134,6 +134,8 @@ public class PlayerChunk {
@ -1493,7 +1493,7 @@ index 48a008e0a..395386f29 100644
} else {
this.a((Packet) (new PacketPlayOutMultiBlockChange(this.dirtyCount, this.dirtyBlocks, this.chunk)));
diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java
index a49b5c81a..5ec7f5819 100644
index a49b5c81a8..5ec7f5819f 100644
--- a/src/main/java/net/minecraft/server/PlayerInteractManager.java
+++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java
@@ -200,6 +200,8 @@ public class PlayerInteractManager {
@ -1506,10 +1506,10 @@ index a49b5c81a..5ec7f5819 100644
public void a(BlockPosition blockposition) {
diff --git a/src/main/java/net/minecraft/server/RegistryBlockID.java b/src/main/java/net/minecraft/server/RegistryBlockID.java
index 8860a0129..fa0d66d63 100644
index 03894df54c..76f6f35bb9 100644
--- a/src/main/java/net/minecraft/server/RegistryBlockID.java
+++ b/src/main/java/net/minecraft/server/RegistryBlockID.java
@@ -47,6 +47,7 @@ public class RegistryBlockID<T> implements Registry { // Paper - Fix decompile e
@@ -47,6 +47,7 @@ public class RegistryBlockID<T> implements Registry<T> {
return Iterators.filter(this.b.iterator(), Predicates.notNull());
}
@ -1518,7 +1518,7 @@ index 8860a0129..fa0d66d63 100644
return this.a.size();
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 90f946e57..ea67b61b2 100644
index 90f946e57a..ea67b61b2b 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -35,6 +35,8 @@ import org.bukkit.generator.ChunkGenerator;
@ -1555,7 +1555,7 @@ index 90f946e57..ea67b61b2 100644
public void a(BlockPosition blockposition, Block block, EnumDirection enumdirection) {
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java b/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java
index 9942f0c75..2da6edc63 100644
index 9942f0c750..2da6edc63e 100644
--- a/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java
@@ -73,7 +73,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {

Datei anzeigen

@ -1,4 +1,4 @@
From 2f16be2d68ab57aac9b4568aa113b15f6b0d6af2 Mon Sep 17 00:00:00 2001
From a1591adb339b39f104073b0e8c1294671a2ebf25 Mon Sep 17 00:00:00 2001
From: cswhite2000 <18whitechristop@gmail.com>
Date: Tue, 21 Aug 2018 19:44:10 -0700
Subject: [PATCH] isChunkGenerated API
@ -6,7 +6,7 @@ Subject: [PATCH] isChunkGenerated API
Resolves #1329
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 0eba3df5..ad548590 100644
index 0eba3df571..ad5485908d 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -85,6 +85,12 @@ public class ChunkProviderServer implements IChunkProvider {
@ -23,7 +23,7 @@ index 0eba3df5..ad548590 100644
public Chunk getLoadedChunkAt(int i, int j) {
long k = ChunkCoordIntPair.a(i, j);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 567e9acb..afb141c6 100644
index 567e9acb13..afb141c629 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -630,6 +630,12 @@ public class CraftWorld implements World {

Datei anzeigen

@ -1,11 +1,11 @@
From d81b977104ba95086af880aff9f93669ea99537f Mon Sep 17 00:00:00 2001
From 1f57f866821be74be996417e22f59eb70b77df8a Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
Date: Thu, 23 Aug 2018 16:14:12 +0800
Subject: [PATCH] Add source block to BlockPhysicsEvent
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 04d0fa1d..64d75934 100644
index 04d0fa1df9..64d75934bc 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -590,7 +590,7 @@ public abstract class World implements IBlockAccess {
@ -18,5 +18,5 @@ index 04d0fa1d..64d75934 100644
if (event.isCancelled()) {
--
2.18.0.windows.1
2.18.0