From ae2fc30b7b89e2ab4c953fb18a5a7d547868560f Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 12 May 2025 20:39:24 +1000 Subject: [PATCH] #3828: Set allocator using Netty system property to apply pooled allocator default globally --- proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 8 ++++++++ .../main/java/net/md_5/bungee/netty/PipelineUtils.java | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 849662a7..5eb05e10 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -262,6 +262,14 @@ public class BungeeCord extends ProxyServer ResourceLeakDetector.setLevel( ResourceLeakDetector.Level.DISABLED ); // Eats performance } + // https://github.com/netty/netty/wiki/Netty-4.2-Migration-Guide + // The adaptive allocator, the new default allocator since Netty 4.2, has some memory issues. + // Setting it globally also ensures that any plugins would also use the pooled allocator. + if ( System.getProperty( "io.netty.allocator.type" ) == null ) + { + System.setProperty( "io.netty.allocator.type", "pooled" ); + } + eventLoops = PipelineUtils.newEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() ); File moduleDirectory = new File( "modules" ); diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index 21664e76..0a916c04 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -1,7 +1,6 @@ package net.md_5.bungee.netty; import com.google.common.base.Preconditions; -import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.Channel; import io.netty.channel.ChannelException; import io.netty.channel.ChannelOption; @@ -219,9 +218,6 @@ public class PipelineUtils { // IP_TOS is not supported (Windows XP / Windows Server 2003) } - // https://github.com/netty/netty/wiki/Netty-4.2-Migration-Guide - // TODO: check for AdaptiveByteBufAllocator - ch.config().setAllocator( PooledByteBufAllocator.DEFAULT ); ch.config().setWriteBufferWaterMark( MARK ); ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );