From 687c302610caca480a332755210be4fb851c4d6e Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sun, 23 Mar 2025 08:19:07 +1100 Subject: [PATCH] Add WriteTimeoutHandler --- proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java | 4 ++++ proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index a73a29c7..684654d2 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -7,6 +7,7 @@ import io.netty.handler.codec.CorruptedFrameException; import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.haproxy.HAProxyMessage; import io.netty.handler.timeout.ReadTimeoutException; +import io.netty.handler.timeout.WriteTimeoutException; import java.io.IOException; import java.net.InetSocketAddress; import java.util.logging.Level; @@ -176,6 +177,9 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter if ( cause instanceof ReadTimeoutException ) { ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - read timed out", handler ); + } else if ( cause instanceof WriteTimeoutException ) + { + ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - write timed out", handler ); } else if ( cause instanceof DecoderException ) { if ( cause instanceof CorruptedFrameException ) 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 2934cdef..d9536149 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 @@ -23,6 +23,7 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.unix.DomainSocketAddress; import io.netty.handler.codec.haproxy.HAProxyMessageDecoder; import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.handler.timeout.WriteTimeoutHandler; import io.netty.incubator.channel.uring.IOUring; import io.netty.incubator.channel.uring.IOUringDatagramChannel; import io.netty.incubator.channel.uring.IOUringEventLoopGroup; @@ -114,6 +115,7 @@ public class PipelineUtils private static final ChannelAcceptor BASE_SERVERSIDE = new Base( true ); private static final KickStringWriter legacyKicker = new KickStringWriter(); public static final String TIMEOUT_HANDLER = "timeout"; + public static final String WRITE_TIMEOUT_HANDLER = "write-timeout"; public static final String PACKET_DECODER = "packet-decoder"; public static final String PACKET_ENCODER = "packet-encoder"; public static final String BOSS_HANDLER = "inbound-boss"; @@ -220,6 +222,7 @@ public class PipelineUtils ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() ); ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); + ch.pipeline().addLast( WRITE_TIMEOUT_HANDLER, new WriteTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); // No encryption bungee -> server, therefore use extra buffer to avoid copying everything for length prepending // Not used bungee -> client as header would need to be encrypted separately through expensive JNI call // TODO: evaluate difference compose vs two buffers