[#989] Fix possible deeadlock on close in SslHandler
This commit is contained in:
parent
984276355c
commit
cf61cc4a0a
|
@ -1551,35 +1551,41 @@ public class SslHandler extends FrameDecoder
|
||||||
* See <a href="https://github.com/netty/netty/issues/305">#305</a> for more details.
|
* See <a href="https://github.com/netty/netty/issues/305">#305</a> for more details.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
public void channelClosed(final ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||||
Throwable cause = null;
|
// Move the fail of the writes to the IO-Thread to prevent possible deadlock
|
||||||
synchronized (pendingUnencryptedWrites) {
|
// See https://github.com/netty/netty/issues/989
|
||||||
for (;;) {
|
ctx.getPipeline().execute(new Runnable() {
|
||||||
PendingWrite pw = pendingUnencryptedWrites.poll();
|
public void run() {
|
||||||
if (pw == null) {
|
Throwable cause = null;
|
||||||
break;
|
synchronized (pendingUnencryptedWrites) {
|
||||||
}
|
for (;;) {
|
||||||
if (cause == null) {
|
PendingWrite pw = pendingUnencryptedWrites.poll();
|
||||||
cause = new ClosedChannelException();
|
if (pw == null) {
|
||||||
}
|
break;
|
||||||
pw.future.setFailure(cause);
|
}
|
||||||
}
|
if (cause == null) {
|
||||||
|
cause = new ClosedChannelException();
|
||||||
|
}
|
||||||
|
pw.future.setFailure(cause);
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
MessageEvent ev = pendingEncryptedWrites.poll();
|
MessageEvent ev = pendingEncryptedWrites.poll();
|
||||||
if (ev == null) {
|
if (ev == null) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
if (cause == null) {
|
||||||
|
cause = new ClosedChannelException();
|
||||||
|
}
|
||||||
|
ev.getFuture().setFailure(cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (cause == null) {
|
|
||||||
cause = new ClosedChannelException();
|
|
||||||
}
|
|
||||||
ev.getFuture().setFailure(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cause != null) {
|
if (cause != null) {
|
||||||
fireExceptionCaught(ctx, cause);
|
fireExceptionCaught(ctx, cause);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
super.channelClosed(ctx, e);
|
super.channelClosed(ctx, e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user