NETTY-428 SslHandler does not trigger an exceptionCaught event for some handshake failure cases.

* Made sure SslHandler.handshake() and SslHandler.close() trigger an exceptionCaught event when failed
This commit is contained in:
Trustin Lee 2011-08-02 15:38:58 +09:00
parent 5f19f4c0b6
commit b969706832
2 changed files with 15 additions and 5 deletions

View File

@ -50,7 +50,7 @@ public class SecureChatClientPipelineFactory implements
SSLEngine engine =
SecureChatSslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true);
//engine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(engine));

View File

@ -329,6 +329,8 @@ public class SslHandler extends FrameDecoder
ChannelHandlerContext ctx = this.ctx;
Channel channel = ctx.getChannel();
ChannelFuture handshakeFuture;
Exception exception = null;
synchronized (handshakeLock) {
if (handshaking) {
return this.handshakeFuture;
@ -340,15 +342,22 @@ public class SslHandler extends FrameDecoder
handshakeFuture = this.handshakeFuture = future(channel);
} catch (Exception e) {
handshakeFuture = this.handshakeFuture = failedFuture(channel, e);
exception = e;
}
}
}
try {
wrapNonAppData(ctx, channel);
} catch (SSLException e) {
handshakeFuture.setFailure(e);
if (exception == null) { // Began handshake successfully.
try {
wrapNonAppData(ctx, channel);
} catch (SSLException e) {
fireExceptionCaught(ctx, e);
handshakeFuture.setFailure(e);
}
} else { // Failed to initiate handshake.
fireExceptionCaught(ctx, exception);
}
return handshakeFuture;
}
@ -371,6 +380,7 @@ public class SslHandler extends FrameDecoder
engine.closeOutbound();
return wrapNonAppData(ctx, channel);
} catch (SSLException e) {
fireExceptionCaught(ctx, e);
return failedFuture(channel, e);
}
}