From 7d5b217d83f15c6b808134223ebbc78c65bc79e3 Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 7 Feb 2019 00:04:29 -0500 Subject: [PATCH] Fix logic error in async chunk loading if a chunk load was cancelled after generating stage started it would short circuit return with a null. however this skipped the creation of the loadTask, which some code would then invoke in requestChunk and trigger an NPE. This then likely left an incomplete corrupt request in the chunk map which then crashes servers. It should fix these isseues Fixes #1775 Fixes #1743 --- ...6-Async-Chunk-Loading-and-Generation.patch | 31 ++++++++++--------- ...-after-profile-lookups-if-not-needed.patch | 28 ++++++++--------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Spigot-Server-Patches/0366-Async-Chunk-Loading-and-Generation.patch b/Spigot-Server-Patches/0366-Async-Chunk-Loading-and-Generation.patch index 28ec9f9471..5756096f3b 100644 --- a/Spigot-Server-Patches/0366-Async-Chunk-Loading-and-Generation.patch +++ b/Spigot-Server-Patches/0366-Async-Chunk-Loading-and-Generation.patch @@ -1,4 +1,4 @@ -From d8c055a6b9588b2fe77fdb73f7200a1a87931599 Mon Sep 17 00:00:00 2001 +From 1e485c2ab878e0d28e6b70eb9ad3ace0c424dfee Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 16:55:04 -0400 Subject: [PATCH] Async Chunk Loading and Generation @@ -1070,10 +1070,10 @@ index 68743a6b7..1dbb03a9a 100644 if (true || worldserver.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD || this.getAllowNether()) { // CraftBukkit diff --git a/src/main/java/net/minecraft/server/PaperAsyncChunkProvider.java b/src/main/java/net/minecraft/server/PaperAsyncChunkProvider.java new file mode 100644 -index 000000000..e9a38f9d9 +index 000000000..896fc94a6 --- /dev/null +++ b/src/main/java/net/minecraft/server/PaperAsyncChunkProvider.java -@@ -0,0 +1,655 @@ +@@ -0,0 +1,656 @@ +/* + * This file is licensed under the MIT License (MIT). + * @@ -1617,6 +1617,18 @@ index 000000000..e9a38f9d9 + } + + synchronized PendingChunkRequest addListener(CompletableFuture future, boolean gen, boolean autoSubmit) { ++ requests.incrementAndGet(); ++ if (loadTask == null) { ++ // Take care of a race condition in that a request could be cancelled after the synchronize ++ // on pendingChunks, but before a listener is added, which would erase these pending tasks. ++ genTask = generationExecutor.createPendingTask(this::generateChunk, taskPriority); ++ loadTask = EXECUTOR.createPendingTask(this, taskPriority); ++ if (autoSubmit) { ++ // We will execute it outside of the synchronized context immediately after ++ loadTask.submit(); ++ } ++ } ++ + if (hasFinished) { + future.complete(chunk); + return new PendingChunkRequest(this); @@ -1632,17 +1644,6 @@ index 000000000..e9a38f9d9 + } + } + -+ requests.incrementAndGet(); -+ if (loadTask == null) { -+ // Take care of a race condition in that a request could be cancelled after the synchronize -+ // on pendingChunks, but before a listener is added, which would erase these pending tasks. -+ genTask = generationExecutor.createPendingTask(this::generateChunk, taskPriority); -+ loadTask = EXECUTOR.createPendingTask(this, taskPriority); -+ if (autoSubmit) { -+ // We will execute it outside of the synchronized context immediately after -+ loadTask.submit(); -+ } -+ } + return new PendingChunkRequest(this, gen); + } + @@ -2315,7 +2316,7 @@ index a9fffa544..19ce77c4a 100644 } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 5fca9e4bd..78adc8714 100644 +index 8dccf9498..75c4592c2 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1021,8 +1021,12 @@ public final class CraftServer implements Server { diff --git a/Spigot-Server-Patches/0392-Don-t-sleep-after-profile-lookups-if-not-needed.patch b/Spigot-Server-Patches/0392-Don-t-sleep-after-profile-lookups-if-not-needed.patch index 6f1cfc4840..30da7eecd5 100644 --- a/Spigot-Server-Patches/0392-Don-t-sleep-after-profile-lookups-if-not-needed.patch +++ b/Spigot-Server-Patches/0392-Don-t-sleep-after-profile-lookups-if-not-needed.patch @@ -1,4 +1,4 @@ -From a8f8a54a79674d324c92a164bd27836c3eb19757 Mon Sep 17 00:00:00 2001 +From af705fcd4e7c9f933bc7f24c3ea4b1a11b6eb9f3 Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 23 Oct 2018 20:25:05 -0400 Subject: [PATCH] Don't sleep after profile lookups if not needed @@ -7,30 +7,30 @@ Mojang was sleeping even if we had no more requests to go after the current one finished, resulting in 100ms lost per profile lookup diff --git a/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java -index 26a743722..6ed3199c3 100644 +index 71e48e87b..23f1447cf 100644 --- a/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -42,6 +42,7 @@ public class YggdrasilGameProfileRepository implements GameProfileRepository { - } - - final int page = 0; + } + + final int page = 0; + boolean hasRequested = false; // Paper - - for (final List request : Iterables.partition(criteria, ENTRIES_PER_PAGE)) { - int failCount = 0; + + for (final List request : Iterables.partition(criteria, ENTRIES_PER_PAGE)) { + int failCount = 0; @@ -67,6 +68,12 @@ public class YggdrasilGameProfileRepository implements GameProfileRepository { - LOGGER.debug("Couldn't find profile {}", name); - callback.onProfileLookupFailed(new GameProfile(null, name), new ProfileNotFoundException("Server did not find the requested profile")); - } + LOGGER.debug("Couldn't find profile {}", name); + callback.onProfileLookupFailed(new GameProfile(null, name), new ProfileNotFoundException("Server did not find the requested profile")); + } + // Paper start + if (!hasRequested) { + hasRequested = true; + continue; + } + // Paper end - - try { - Thread.sleep(DELAY_BETWEEN_PAGES); + + try { + Thread.sleep(DELAY_BETWEEN_PAGES); -- 2.20.1