Invalid memory configuration for netty maxDirectMemory in native image
I thinks this only concerns native image builds.

Setting either 
-XX:MaxDirectMemorySize
or 
-Dio.netty.maxDirectMemory
does not work at runtime and runtime memory is incorrectly reflected in io.netty.util.internal.PlatformDependent.DIRECT_MEMORY_LIMIT
at runtime.

i think the problem is that io.netty.buffer.PooledByteBufAllocator uses  io.netty.util.internal.PlatformDependent
which is not initialized during runtime but build time.

I tested this with Quarkus 1.10.5.Final, but looking at the current code of NettyProcessor shows that PlatformDependent is still not initialized at runtime, only PooledByteBufAllocator is.


diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
index 069fb756162..de1471c3ae4 100644
--- a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
+++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
@@ -93,7 +93,8 @@ NativeImageConfigBuildItem build(
         String maxOrder = calculateMaxOrder(config.allocatorMaxOrder, minMaxOrderBuildItems, false);
 
         NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder()
-                //.addNativeImageSystemProperty("io.netty.noUnsafe", "true")
+                // disable unsafe usage to allow io.netty.internal.PlarformDependent0 to be reinitialized without issues
+                .addNativeImageSystemProperty("io.netty.noUnsafe", "true")
                 // Use small chunks to avoid a lot of wasted space. Default is 16mb * arenas (derived from core count)
                 // Since buffers are cached to threads, the malloc overhead is temporary anyway
                 .addNativeImageSystemProperty("io.netty.allocator.maxOrder", maxOrder)
@@ -109,6 +110,9 @@ NativeImageConfigBuildItem build(
                 .addRuntimeInitializedClass("io.netty.buffer.ByteBufUtil")
                 // The default channel id uses the process id, it should not be cached in the native image.
                 .addRuntimeInitializedClass("io.netty.channel.DefaultChannelId")
+                // Make sure to re-initialize platform dependent classes/values at runtime
+                .addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent")
+                .addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent0")
                 .addNativeImageSystemProperty("io.netty.leakDetection.level", "DISABLED");
 
         if (QuarkusClassLoader.isClassPresentAtRuntime("io.netty.handler.codec.http.HttpObjectEncoder")) {
['extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java']