Do not treat errors as decoder exception (redux)
Motivation: Today when Netty encounters a general error while decoding it treats this as a decoder exception. However, for fatal causes this should not be treated as such, instead the fatal error should be carried up the stack without the callee having to unwind causes. This was probably done for byte to byte message decoder but is now done for all decoders. Modifications: Instead of translating any error to a decoder exception, we let those unwind out the stack (note that finally blocks still execute) except in places where an event needs to fire where we fire with the error instead of wrapping in a decoder exception. Result: Fatal errors will not be treated as innocent decoder exceptions.
This commit is contained in:
parent
3637bb8ce3
commit
b5b53daf91
@ -355,16 +355,16 @@ public class HAProxyMessageDecoder extends ByteToMessageDecoder {
|
|||||||
fail(ctx, "header length (" + length + ") exceeds the allowed maximum (" + maxLength + ')', null);
|
fail(ctx, "header length (" + length + ") exceeds the allowed maximum (" + maxLength + ')', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fail(final ChannelHandlerContext ctx, String errMsg, Throwable t) {
|
private void fail(final ChannelHandlerContext ctx, String errMsg, Exception e) {
|
||||||
finished = true;
|
finished = true;
|
||||||
ctx.close(); // drop connection immediately per spec
|
ctx.close(); // drop connection immediately per spec
|
||||||
HAProxyProtocolException ppex;
|
HAProxyProtocolException ppex;
|
||||||
if (errMsg != null && t != null) {
|
if (errMsg != null && e != null) {
|
||||||
ppex = new HAProxyProtocolException(errMsg, t);
|
ppex = new HAProxyProtocolException(errMsg, e);
|
||||||
} else if (errMsg != null) {
|
} else if (errMsg != null) {
|
||||||
ppex = new HAProxyProtocolException(errMsg);
|
ppex = new HAProxyProtocolException(errMsg);
|
||||||
} else if (t != null) {
|
} else if (e != null) {
|
||||||
ppex = new HAProxyProtocolException(t);
|
ppex = new HAProxyProtocolException(e);
|
||||||
} else {
|
} else {
|
||||||
ppex = new HAProxyProtocolException();
|
ppex = new HAProxyProtocolException();
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
|
|||||||
}
|
}
|
||||||
} catch (DecoderException e) {
|
} catch (DecoderException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable cause) {
|
} catch (Exception cause) {
|
||||||
throw new DecoderException(cause);
|
throw new DecoderException(cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,6 @@ import io.netty.handler.codec.ByteToMessageDecoder;
|
|||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.DomainNameMapping;
|
import io.netty.util.DomainNameMapping;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.concurrent.Future;
|
|
||||||
import io.netty.util.concurrent.FutureListener;
|
|
||||||
import io.netty.util.concurrent.Promise;
|
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
@ -242,7 +239,7 @@ public class SniHandler extends ByteToMessageDecoder {
|
|||||||
break loop;
|
break loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Exception e) {
|
||||||
// unexpected encoding, ignore sni and use default
|
// unexpected encoding, ignore sni and use default
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Unexpected client hello packet: " + ByteBufUtil.hexDump(in), e);
|
logger.debug("Unexpected client hello packet: " + ByteBufUtil.hexDump(in), e);
|
||||||
|
Loading…
Reference in New Issue
Block a user