[#1475] Correctly handle writes with empty MessageList in SslHandler

This commit is contained in:
Norman Maurer 2013-06-20 16:07:36 +02:00 committed by Trustin Lee
parent ad73dce7a1
commit e06fcdbc6a
2 changed files with 20 additions and 12 deletions

View File

@ -392,17 +392,28 @@ public class SslHandler
ctx.write(msgs, promise);
return;
}
for (int i = 0; i < msgs.size(); i++) {
ByteBuf msg = (ByteBuf) msgs.get(i);
ChannelPromise cp;
if (i + 1 == msgs.size()) {
cp = promise;
try {
if (msgs.isEmpty()) {
// if the MessageList is empty we need to add an empty buffer as pending write as otherwise
// the promise will never be notified.
// See https://github.com/netty/netty/issues/1475
pendingUnencryptedWrites.add(new PendingWrite(Unpooled.EMPTY_BUFFER, promise));
} else {
cp = ctx.newPromise();
for (int i = 0; i < msgs.size(); i++) {
ByteBuf msg = (ByteBuf) msgs.get(i);
ChannelPromise cp;
if (i + 1 == msgs.size()) {
cp = promise;
} else {
cp = ctx.newPromise();
}
pendingUnencryptedWrites.add(new PendingWrite(msg, cp));
}
}
pendingUnencryptedWrites.add(new PendingWrite(msg, cp));
flush0(ctx);
} finally {
msgs.recycle();
}
flush0(ctx);
}
private void flush0(ChannelHandlerContext ctx) throws SSLException {

View File

@ -111,10 +111,7 @@ 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);
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();
}
future.sync();
i += length;
}