diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index ad2deae6c7..04a7c416bb 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -617,13 +617,11 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha ChannelOutboundBuffer outboundBuffer = this.outboundBuffer; this.outboundBuffer = null; // Disallow adding any messages and flushes to outboundBuffer. + Throwable error = null; try { doClose(); - closeFuture.setClosed(); - safeSetSuccess(promise); } catch (Throwable t) { - closeFuture.setClosed(); - safeSetFailure(promise, t); + error = t; } // Fail all the queued messages @@ -647,6 +645,14 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha } }); } + + // Now complete the closeFuture and promise. + closeFuture.setClosed(); + if (error != null) { + safeSetFailure(promise, error); + } else { + safeSetSuccess(promise); + } } }