diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java index 0d2ec29cf9..f1d4da76e1 100644 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java +++ b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java @@ -134,7 +134,7 @@ public class RxtxChannel extends OioByteStreamChannel { public void connect( final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { - if (!ensureOpen(promise)) { + if (!promise.setUncancellable() || !ensureOpen(promise)) { return; } diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index 7404bae4bc..194c4a7f9a 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -418,7 +418,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha try { // check if the channel is still open as it could be closed in the mean time when the register // call was outside of the eventLoop - if (!ensureOpen(promise)) { + if (!promise.setUncancellable() || !ensureOpen(promise)) { return; } doRegister(); @@ -442,7 +442,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha @Override public final void bind(final SocketAddress localAddress, final ChannelPromise promise) { - if (!ensureOpen(promise)) { + if (!promise.setUncancellable() || !ensureOpen(promise)) { return; } @@ -480,6 +480,10 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha @Override public final void disconnect(final ChannelPromise promise) { + if (!promise.setUncancellable()) { + return; + } + boolean wasActive = isActive(); try { doDisconnect(); @@ -502,6 +506,10 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha @Override public final void close(final ChannelPromise promise) { + if (!promise.setUncancellable()) { + return; + } + if (inFlush0) { invokeLater(new Runnable() { @Override diff --git a/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java b/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java index 08297d5a14..3c4453fbbe 100644 --- a/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java +++ b/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java @@ -55,12 +55,7 @@ public abstract class AbstractOioChannel extends AbstractChannel { public void connect( final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { - if (!ensureOpen(promise)) { - return; - } - - if (!promise.setUncancellable()) { - close(voidPromise()); + if (!promise.setUncancellable() || !ensureOpen(promise)) { return; }