2021-08-26 04:16:27 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 8 Aug 2021 16:26:46 -0700
Subject: [PATCH] Do not submit profile lookups to worldgen threads
They block. On network I/O.
If enough tasks are submitted the server will eventually stall
out due to a sync load, as the worldgen threads will be
stalling on profile lookups.
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
2024-12-03 19:05:31 +01:00
index a88cfb92dea57d2f9abc029cea94a1b921f66766..3d5bca1b637234df48ca3228c7ffbce21116a0c7 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/Util.java
+++ b/src/main/java/net/minecraft/Util.java
2024-10-22 22:38:26 +02:00
@@ -95,6 +95,22 @@ public class Util {
private static final TracingExecutor BACKGROUND_EXECUTOR = makeExecutor("Main");
private static final TracingExecutor IO_POOL = makeIoExecutor("IO-Worker-", false);
private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true);
2021-08-26 04:16:27 +02:00
+ // Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
+ public static final ExecutorService PROFILE_EXECUTOR = Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
+
+ private final AtomicInteger count = new AtomicInteger();
+
+ @Override
+ public Thread newThread(Runnable run) {
+ Thread ret = new Thread(run);
+ ret.setName("Profile Lookup Executor #" + this.count.getAndIncrement());
+ ret.setUncaughtExceptionHandler((Thread thread, Throwable throwable) -> {
2022-02-28 23:02:20 +01:00
+ LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable);
2021-08-26 04:16:27 +02:00
+ });
+ return ret;
+ }
+ });
+ // Paper end - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
2022-07-27 21:49:24 +02:00
private static final DateTimeFormatter FILENAME_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT);
2024-04-24 03:25:14 +02:00
public static final int LINEAR_LOOKUP_THRESHOLD = 8;
2024-06-13 20:09:28 +02:00
private static final Set<String> ALLOWED_UNTRUSTED_LINK_PROTOCOLS = Set.of("http", "https");
2021-08-26 04:16:27 +02:00
diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2024-10-22 22:38:26 +02:00
index c89f4a885982f06823886c81fd386b8de029a3dd..416b26c2ab62b29d640169166980e398d5824b14 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
+++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2023-12-28 21:47:57 +01:00
@@ -169,7 +169,7 @@ public class GameProfileCache {
2021-08-26 04:16:27 +02:00
} else {
2023-09-21 22:35:39 +02:00
CompletableFuture<Optional<GameProfile>> completablefuture1 = CompletableFuture.supplyAsync(() -> {
2021-08-26 04:16:27 +02:00
return this.get(username);
2024-10-22 22:38:26 +02:00
- }, Util.backgroundExecutor().forName("getProfile")).whenCompleteAsync((optional, throwable) -> {
2024-01-22 19:01:10 +01:00
+ }, Util.PROFILE_EXECUTOR).whenCompleteAsync((optional, throwable) -> { // Paper - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
2021-08-26 04:16:27 +02:00
this.requests.remove(username);
2023-09-21 22:35:39 +02:00
}, this.executor);
2021-08-26 04:16:27 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
2024-10-22 22:38:26 +02:00
index 59187889db52ccb132460b0e937d0bd5cbeb77f4..4b7176779c455a876419a497a8178163a68553fc 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
2024-04-24 03:25:14 +02:00
@@ -105,7 +105,7 @@ public class SkullBlockEntity extends BlockEntity {
ProfileResult profileResult = apiServices.sessionService().fetchProfile(uuid, true);
return Optional.ofNullable(profileResult).map(ProfileResult::profile);
2023-09-21 22:35:39 +02:00
}
2024-10-22 22:38:26 +02:00
- }, Util.backgroundExecutor().forName("fetchProfile"));
2024-01-22 19:01:10 +01:00
+ }, Util.PROFILE_EXECUTOR); // Paper - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
2023-09-21 22:35:39 +02:00
}
2024-04-24 03:25:14 +02:00
public static void clear() {
2022-07-03 23:55:56 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
2024-10-22 22:38:26 +02:00
index 26a7c2d37e6a8284ab444a9edad967bdcad1e5a3..210fdad5f2041368fc359b275f1cbf05b70b6989 100644
2022-07-03 23:55:56 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
+++ b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
2024-09-15 21:39:53 +02:00
@@ -161,7 +161,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
2022-07-03 23:55:56 +02:00
@Override
public CompletableFuture<PlayerProfile> update() {
- return CompletableFuture.supplyAsync(this::getUpdatedProfile, Util.backgroundExecutor());
2024-01-22 19:01:10 +01:00
+ return CompletableFuture.supplyAsync(this::getUpdatedProfile, Util.PROFILE_EXECUTOR); // Paper - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
2022-07-03 23:55:56 +02:00
}
private CraftPlayerProfile getUpdatedProfile() {