Fixed a bug: NETTY-56 (The ChannFuture returned by SslHandler.handshake() is not completed when the associated Channel is closed during handshake.)

This commit is contained in:
Trustin Lee 2008-10-03 02:53:57 +00:00
parent b378c083ec
commit dddf14f79a
2 changed files with 17 additions and 1 deletions

View File

@ -25,6 +25,7 @@ package org.jboss.netty.handler.ssl;
import static org.jboss.netty.channel.Channels.*;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@ -339,6 +340,15 @@ public class SslHandler extends FrameDecoder {
@Override
public void channelDisconnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception {
// Make sure the handshake future is notified when a connection has
// been closed during handshake.
synchronized (handshakeLock) {
if (handshaking) {
handshakeFuture.setFailure(new ClosedChannelException());
}
}
super.channelDisconnected(ctx, e);
unwrap(ctx, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
engine.closeOutbound();

View File

@ -124,7 +124,13 @@ public abstract class AbstractSocketSslEchoTest {
assertTrue(ccf.awaitUninterruptibly().isSuccess());
Channel cc = ccf.getChannel();
assertTrue(cc.getPipeline().get(SslHandler.class).handshake(cc).awaitUninterruptibly().isSuccess());
ChannelFuture hf = cc.getPipeline().get(SslHandler.class).handshake(cc);
hf.awaitUninterruptibly();
if (!hf.isSuccess() && ch.exception.get() != null) {
ch.exception.get().printStackTrace();
}
assertTrue(hf.isSuccess());
for (int i = 0; i < data.length;) {
int length = Math.min(random.nextInt(1024 * 64), data.length - i);