From 32fdc838417d63bb807cdd5a992c18ebd399f290 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 24 May 2013 14:16:43 +1000 Subject: [PATCH] Close #383 - swallow exceptions once and for all --- .../net/md_5/bungee/netty/HandlerBoss.java | 3 +-- .../md_5/bungee/netty/OutboundHandler.java | 25 +++++++++++++++++++ .../net/md_5/bungee/netty/PipelineUtils.java | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/netty/OutboundHandler.java 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 f4214d0c..9e311d58 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 @@ -5,7 +5,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.handler.timeout.ReadTimeoutException; import java.io.IOException; -import java.nio.channels.ClosedChannelException; import java.util.logging.Level; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.connection.CancelSendSignal; @@ -85,7 +84,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter } else if ( cause instanceof IOException ) { ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - IOException: " + cause.getMessage() ); - } else if ( !( cause instanceof ClosedChannelException ) ) + } else { ProxyServer.getInstance().getLogger().log( Level.SEVERE, handler + " - encountered exception", cause ); } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/OutboundHandler.java b/proxy/src/main/java/net/md_5/bungee/netty/OutboundHandler.java new file mode 100644 index 00000000..53789451 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/netty/OutboundHandler.java @@ -0,0 +1,25 @@ +package net.md_5.bungee.netty; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOperationHandlerAdapter; +import io.netty.channel.ChannelPromise; +import java.nio.channels.ClosedChannelException; + +public class OutboundHandler extends ChannelOperationHandlerAdapter +{ + + @Override + public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception + { + ctx.flush( promise ); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception + { + if ( !( cause instanceof ClosedChannelException ) ) + { + ctx.fireExceptionCaught( cause ); + } + } +} 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 1b7ecdc7..26167488 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 @@ -58,6 +58,8 @@ public class PipelineUtils { // IP_TOS is not supported (Windows XP / Windows Server 2003) } + + ch.pipeline().addLast( "outbound", new OutboundHandler() ); ch.pipeline().addLast( "timer", new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); ch.pipeline().addLast( "decoder", new PacketDecoder( PacketDefinitions.VANILLA_PROTOCOL ) ); ch.pipeline().addLast( "packet-encoder", packetEncoder );