Correctly have exceptions thrown from decode(...) method be wrapped with DecodingException

Motivation:

Normally if a decoder produces an exception its wrapped with DecodingException. This is not the cause for NotSslRecordException in SslHandler and SniHandler.

Modifications:

Just throw the NotSslRecordException exception for decode(...) and so ensure its correctly wrapped in a DecodingException before its passed through the pipeline.

Result:

Consist behavior.
This commit is contained in:
Norman Maurer 2017-02-23 20:44:11 +01:00
parent d54ed19e2a
commit e39718bc8d
2 changed files with 8 additions and 5 deletions

View File

@ -22,6 +22,10 @@ import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.util.CharsetUtil;
import io.netty.util.DomainNameMapping;
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.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -109,10 +113,9 @@ public class SniHandler extends ByteToMessageDecoder {
NotSslRecordException e = new NotSslRecordException(
"not an SSL/TLS record: " + ByteBufUtil.hexDump(in));
in.skipBytes(in.readableBytes());
ctx.fireExceptionCaught(e);
SslUtils.notifyHandshakeFailure(ctx, e);
return;
throw e;
}
if (len == SslUtils.NOT_ENOUGH_DATA ||
writerIndex - readerIndex - SslUtils.SSL_RECORD_HEADER_LENGTH < len) {
@ -221,7 +224,7 @@ public class SniHandler extends ByteToMessageDecoder {
select(ctx, IDN.toASCII(hostname,
IDN.ALLOW_UNASSIGNED).toLowerCase(Locale.US));
} catch (Throwable t) {
ctx.fireExceptionCaught(t);
PlatformDependent.throwException(t);
}
return;
} else {
@ -265,7 +268,7 @@ public class SniHandler extends ByteToMessageDecoder {
if (sslHandler != null) {
ReferenceCountUtil.safeRelease(sslHandler.engine());
}
ctx.fireExceptionCaught(cause);
PlatformDependent.throwException(cause);
}
}

View File

@ -1068,7 +1068,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
// be released because the user will remove the SslHandler in an exceptionCaught(...) implementation.
setHandshakeFailure(ctx, e);
ctx.fireExceptionCaught(e);
throw e;
}
}