From dbaedeb005d16f841635ccc6acfc619e977b149e Mon Sep 17 00:00:00 2001 From: masmc05 Date: Thu, 23 Apr 2026 22:54:21 +0200 Subject: [PATCH] Call blocking events on virtual threads --- ...e-Velocity-compression-and-cipher-natives.patch | 4 ++-- .../ServerLoginPacketListenerImpl.java.patch | 14 ++++++-------- .../paper/connection/PaperConfigurationTask.java | 6 +++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/paper-server/patches/features/0008-Use-Velocity-compression-and-cipher-natives.patch b/paper-server/patches/features/0008-Use-Velocity-compression-and-cipher-natives.patch index e0ec15538d0b..9b661dcf8572 100644 --- a/paper-server/patches/features/0008-Use-Velocity-compression-and-cipher-natives.patch +++ b/paper-server/patches/features/0008-Use-Velocity-compression-and-cipher-natives.patch @@ -333,10 +333,10 @@ index b266e4f7b437578356568d86910e3b428ee66523..0b57e3bcd0319e4e9571fddbcb85db5a .add( new ServerBootstrap() diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java -index 8203765d5570644b4c8f6790f361bca2c7066b25..718f00ad9c587a4b0c12f351c10d462113f16ac3 100644 +index 7e316c72ce75d55b1d93ba9c83bc86bd95bf12fa..d35001257f73b335fed241084ebdf7328c9c051f 100644 --- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java -@@ -245,11 +245,9 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, +@@ -243,11 +243,9 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, } SecretKey secretKey = packet.getSecretKey(serverPrivateKey); diff --git a/paper-server/patches/sources/net/minecraft/server/network/ServerLoginPacketListenerImpl.java.patch b/paper-server/patches/sources/net/minecraft/server/network/ServerLoginPacketListenerImpl.java.patch index cc8a081147a0..17b22ab4fff8 100644 --- a/paper-server/patches/sources/net/minecraft/server/network/ServerLoginPacketListenerImpl.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/network/ServerLoginPacketListenerImpl.java.patch @@ -13,7 +13,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, TickablePacketListener { private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0); private static final Logger LOGGER = LogUtils.getLogger(); -+ private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads ++ private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("User Authenticator #", 0).uncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).factory()); // Paper - Virtual authenticator threads private static final int MAX_TICKS_BEFORE_LOGIN = 600; private final byte[] challenge; private final MinecraftServer server; @@ -104,7 +104,7 @@ this.requestedUsername = packet.name(); GameProfile singleplayerProfile = this.server.getSingleplayerProfile(); if (singleplayerProfile != null && this.requestedUsername.equalsIgnoreCase(singleplayerProfile.name())) { -@@ -127,7 +_,32 @@ +@@ -127,7 +_,30 @@ this.state = ServerLoginPacketListenerImpl.State.KEY; this.connection.send(new ClientboundHelloPacket("", this.server.getKeyPair().getPublic().getEncoded(), this.challenge, true)); } else { @@ -119,8 +119,7 @@ + return; + } + // Paper end - Add Velocity IP Forwarding Support -+ // CraftBukkit start -+ // Paper start - Cache authenticator threads ++ // Paper start - Virtual authenticator threads + authenticatorPool.execute(() -> { + try { + GameProfile gameprofile = ServerLoginPacketListenerImpl.this.createOfflineProfile(ServerLoginPacketListenerImpl.this.requestedUsername); // Spigot @@ -133,8 +132,7 @@ + ServerLoginPacketListenerImpl.this.server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + ServerLoginPacketListenerImpl.this.requestedUsername, ex); + } + }); -+ // Paper end - Cache authenticator threads -+ // CraftBukkit end ++ // Paper end - Virtual authenticator threads } } } @@ -169,7 +167,7 @@ } - Thread thread = new Thread("User Authenticator #" + UNIQUE_THREAD_ID.incrementAndGet()) { -+ // Paper start - Cache authenticator threads ++ // Paper start - Virtual authenticator threads + authenticatorPool.execute(new Runnable() { { Objects.requireNonNull(ServerLoginPacketListenerImpl.this); @@ -222,7 +220,7 @@ - thread.start(); - } + }); -+ // Paper end - Cache authenticator threads ++ // Paper end - Virtual authenticator threads + } + + // CraftBukkit start diff --git a/paper-server/src/main/java/io/papermc/paper/connection/PaperConfigurationTask.java b/paper-server/src/main/java/io/papermc/paper/connection/PaperConfigurationTask.java index 362056053164..e3fefbd97191 100644 --- a/paper-server/src/main/java/io/papermc/paper/connection/PaperConfigurationTask.java +++ b/paper-server/src/main/java/io/papermc/paper/connection/PaperConfigurationTask.java @@ -1,6 +1,5 @@ package io.papermc.paper.connection; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.mojang.logging.LogUtils; import io.papermc.paper.event.connection.configuration.AsyncPlayerConnectionConfigureEvent; import java.util.concurrent.ExecutorService; @@ -15,8 +14,9 @@ public class PaperConfigurationTask implements ConfigurationTask { private static final Logger LOGGER = LogUtils.getClassLogger(); - public static final ExecutorService CONFIGURATION_POOL = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Configuration Thread #%d") - .setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); + public static final ExecutorService CONFIGURATION_POOL = Executors.newThreadPerTaskExecutor( + Thread.ofVirtual().name("Configuration Thread #", 0).uncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).factory() + ); public static final ConfigurationTask.Type TYPE = new ConfigurationTask.Type("paper_event_handling");