From 667610c251f29a488156f513d06a2a9b110469b0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 28 Nov 2019 15:22:26 -0500 Subject: [PATCH 1/4] Fix command block tab complete on <=1.12.2 --- .../proxy/connection/client/ClientPlaySessionHandler.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index dc4058fc5..2072372f5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -417,10 +417,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { * @param response the tab complete response from the backend */ public void handleTabCompleteResponse(TabCompleteResponse response) { - if (outstandingTabComplete != null) { - if (outstandingTabComplete.isAssumeCommand()) { - return; // used for command blocks which can't run Velocity commands anyway - } + if (outstandingTabComplete != null && !outstandingTabComplete.isAssumeCommand()) { if (outstandingTabComplete.getCommand().startsWith("/")) { this.finishCommandTabComplete(outstandingTabComplete, response); } else { From 2f55912995adf182273e79c61ce95eb41a6b52be Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 29 Nov 2019 12:03:38 -0500 Subject: [PATCH 2/4] Graceful fallback when /tmp is amounted noexec on Linux Fixes #260 --- .../java/com/velocitypowered/natives/util/Natives.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/native/src/main/java/com/velocitypowered/natives/util/Natives.java b/native/src/main/java/com/velocitypowered/natives/util/Natives.java index 7e4f05e97..c3f28cc3b 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/Natives.java +++ b/native/src/main/java/com/velocitypowered/natives/util/Natives.java @@ -38,7 +38,12 @@ public class Natives { // Well, it doesn't matter... } })); - System.load(tempFile.toAbsolutePath().toString()); + + try { + System.load(tempFile.toAbsolutePath().toString()); + } catch (UnsatisfiedLinkError e) { + throw new NativeSetupException("Unable to load native " + tempFile.toAbsolutePath(), e); + } } catch (IOException e) { throw new NativeSetupException("Unable to copy natives", e); } From 75359256b36cc07155a9ecbf549d756876a17c13 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 29 Nov 2019 14:26:59 -0500 Subject: [PATCH 3/4] Introduce velocity.natives-tmpdir property for properly handling noexec /tmp --- .../com/velocitypowered/natives/util/Natives.java | 12 +++++++++++- .../java/com/velocitypowered/proxy/Velocity.java | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/native/src/main/java/com/velocitypowered/natives/util/Natives.java b/native/src/main/java/com/velocitypowered/natives/util/Natives.java index c3f28cc3b..e63c87c20 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/Natives.java +++ b/native/src/main/java/com/velocitypowered/natives/util/Natives.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardCopyOption; public class Natives { @@ -24,12 +25,12 @@ public class Natives { private static Runnable copyAndLoadNative(String path) { return () -> { try { - Path tempFile = Files.createTempFile("native-", path.substring(path.lastIndexOf('.'))); InputStream nativeLib = Natives.class.getResourceAsStream(path); if (nativeLib == null) { throw new IllegalStateException("Native library " + path + " not found."); } + Path tempFile = createTemporaryNativeFilename(path.substring(path.lastIndexOf('.'))); Files.copy(nativeLib, tempFile, StandardCopyOption.REPLACE_EXISTING); Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { @@ -50,6 +51,15 @@ public class Natives { }; } + private static Path createTemporaryNativeFilename(String ext) throws IOException { + String temporaryFolderPath = System.getProperty("velocity.natives-tmpdir"); + if (temporaryFolderPath != null) { + return Files.createTempFile(Paths.get(temporaryFolderPath), "native-", ext); + } else { + return Files.createTempFile("native-", ext); + } + } + public static final NativeCodeLoader compress = new NativeCodeLoader<>( ImmutableList.of( new NativeCodeLoader.Variant<>(NativeConstraints.MACOS, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java index d00274735..1a7e33c65 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java @@ -23,6 +23,12 @@ public class Velocity { if (System.getProperty("io.netty.allocator.maxOrder") == null) { System.setProperty("io.netty.allocator.maxOrder", "9"); } + + // If Velocity's natives are being extracted to a different temporary directory, make sure the + // Netty natives are extracted there as well + if (System.getProperty("velocity.natives-tmpdir") != null) { + System.setProperty("io.netty.native.workdir", System.getProperty("velocity.natives-tmpdir")); + } } /** From 8c3f7e2eccf2e326c1f20b8ba9e1a12646a0cbd4 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 1 Dec 2019 15:17:17 -0500 Subject: [PATCH 4/4] Optimize DNS resolution logic for AsyncHttpClient --- .../DnsAddressResolverGroupNameResolverAdapter.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/netty/DnsAddressResolverGroupNameResolverAdapter.java b/proxy/src/main/java/com/velocitypowered/proxy/network/netty/DnsAddressResolverGroupNameResolverAdapter.java index f76a160c9..169b60a49 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/netty/DnsAddressResolverGroupNameResolverAdapter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/netty/DnsAddressResolverGroupNameResolverAdapter.java @@ -7,6 +7,7 @@ import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.Promise; +import io.netty.util.internal.ThreadExecutorMap; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -61,13 +62,7 @@ public class DnsAddressResolverGroupNameResolverAdapter extends InetNameResolver } private EventExecutor findExecutor() { - for (EventExecutor executor : group) { - if (executor.inEventLoop()) { - return executor; - } - } - - // otherwise, pick one - return group.next(); + EventExecutor current = ThreadExecutorMap.currentExecutor(); + return current == null ? group.next() : current; } }