[#1464] Make sure the ChannelPromise for writes is notified while using SslHandler

This commit is contained in:
Norman Maurer 2013-06-20 15:42:50 +02:00 committed by Trustin Lee
parent cfb3b977a1
commit ad73dce7a1
2 changed files with 18 additions and 10 deletions

View File

@ -406,16 +406,15 @@ public class SslHandler
}
private void flush0(ChannelHandlerContext ctx) throws SSLException {
boolean unwrapLater = false;
PendingWrite pending = null;
ByteBuf out = null;
ChannelPromise promise = null;
try {
for (;;) {
if (out == null) {
out = ctx.alloc().buffer();
}
pending = pendingUnencryptedWrites.peek();
PendingWrite pending = pendingUnencryptedWrites.peek();
if (pending == null) {
break;
}
@ -423,7 +422,10 @@ public class SslHandler
if (!pending.buf.isReadable()) {
pending.buf.release();
promise = pending.promise;
pendingUnencryptedWrites.remove();
} else {
promise = null;
}
if (result.getStatus() == Status.CLOSED) {
@ -445,8 +447,9 @@ public class SslHandler
} else {
switch (result.getHandshakeStatus()) {
case NEED_WRAP:
if (!pending.buf.isReadable()) {
ctx.write(out, pending.promise);
if (promise != null) {
ctx.write(out, promise);
promise = null;
} else {
ctx.write(out);
}
@ -488,14 +491,14 @@ public class SslHandler
throw e;
} finally {
if (out != null && out.isReadable()) {
if (pending != null && !pending.buf.isReadable()) {
ctx.write(out, pending.promise);
if (promise != null) {
ctx.write(out, promise);
} else {
ctx.write(out);
}
out = null;
} else if (pending != null && !pending.buf.isReadable()) {
pending.promise.setSuccess();
} else if (promise != null) {
promise.trySuccess();
}
if (out != null) {
out.release();

View File

@ -20,6 +20,7 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
@ -109,7 +110,11 @@ public class SocketSslEchoTest extends AbstractSocketTest {
for (int i = FIRST_MESSAGE_SIZE; i < data.length;) {
int length = Math.min(random.nextInt(1024 * 64), data.length - i);
cc.write(Unpooled.wrappedBuffer(data, i, length));
ChannelFuture future = cc.write(Unpooled.wrappedBuffer(data, i, length));
// TODO: Remove me as it seems like ChunkWriteHandler has a bug which let it hang here
if (!chunkWriteHandler) {
future.sync();
}
i += length;
}