Ensure SslHandler.close(...) will not throw exception if flush of pending messages fails
Motivation: When SslHandler.close(...) is called (as part of Channel.close()). it will also try to flush pending messages. This may fail for various reasons, but we still should propergate the close operation Modifications: - Ensure flush(...) itself will not throw an Exception if we was able to at least fail one pending promise (which should always be the case). - If flush(...) fails as part of close ensure we still close the channel and then rethrow. Result: No more lost close operations possible if an exception is thrown during close
This commit is contained in:
parent
e4154bcb0b
commit
2d111e0980
@ -489,6 +489,11 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
||||
}
|
||||
try {
|
||||
wrap(ctx, false);
|
||||
} catch (Throwable cause) {
|
||||
// Fail pending writes.
|
||||
pendingUnencryptedWrites.removeAndFailAll(cause);
|
||||
|
||||
PlatformDependent.throwException(cause);
|
||||
} finally {
|
||||
// We may have written some parts of data before an exception was thrown so ensure we always flush.
|
||||
// See https://github.com/netty/netty/issues/3900#issuecomment-172481830
|
||||
@ -1247,9 +1252,12 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
||||
engine.closeOutbound();
|
||||
|
||||
ChannelPromise closeNotifyFuture = ctx.newPromise();
|
||||
write(ctx, Unpooled.EMPTY_BUFFER, closeNotifyFuture);
|
||||
flush(ctx);
|
||||
safeClose(ctx, closeNotifyFuture, promise);
|
||||
try {
|
||||
write(ctx, Unpooled.EMPTY_BUFFER, closeNotifyFuture);
|
||||
flush(ctx);
|
||||
} finally {
|
||||
safeClose(ctx, closeNotifyFuture, promise);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user