diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index be004e2cd6ef..ee36e6335c98 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -523,22 +523,25 @@ public void run() { } // fail all queued messages - ChannelOutboundBuffer outboundBuffer = this.outboundBuffer; - outboundBuffer.failFlushed(CLOSED_CHANNEL_EXCEPTION); - outboundBuffer.failUnflushed(CLOSED_CHANNEL_EXCEPTION); - outboundBuffer.recycle(); - this.outboundBuffer = null; + try { + ChannelOutboundBuffer outboundBuffer = this.outboundBuffer; + outboundBuffer.failFlushed(CLOSED_CHANNEL_EXCEPTION); + outboundBuffer.failUnflushed(CLOSED_CHANNEL_EXCEPTION); + outboundBuffer.recycle(); + } finally { + outboundBuffer = null; + + if (wasActive && !isActive()) { + invokeLater(new Runnable() { + @Override + public void run() { + pipeline.fireChannelInactive(); + } + }); + } - if (wasActive && !isActive()) { - invokeLater(new Runnable() { - @Override - public void run() { - pipeline.fireChannelInactive(); - } - }); + deregister(voidPromise()); } - - deregister(voidPromise()); } else { // Closed already. promise.setSuccess();