Fixes the problem where the promise of the outbound operation that causes a channel closure is notified after channelInactive()

- Fixes #1897
This commit is contained in:
Trustin Lee 2013-10-08 12:24:16 +09:00
parent 3c7d458c6e
commit 8864792499
4 changed files with 7 additions and 9 deletions

View File

@ -470,8 +470,8 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
try {
doBind(localAddress);
} catch (Throwable t) {
closeIfClosed();
promise.setFailure(t);
closeIfClosed();
return;
}
if (!wasActive && isActive()) {
@ -491,8 +491,8 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
try {
doDisconnect();
} catch (Throwable t) {
closeIfClosed();
promise.setFailure(t);
closeIfClosed();
return;
}
if (wasActive && !isActive()) {
@ -503,8 +503,8 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
}
});
}
closeIfClosed(); // doDisconnect() might have closed the channel
promise.setSuccess();
closeIfClosed(); // doDisconnect() might have closed the channel
}
@Override

View File

@ -35,6 +35,7 @@ import java.nio.channels.ClosedChannelException;
import java.nio.channels.ConnectionPendingException;
import java.nio.channels.NotYetConnectedException;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Queue;
/**
@ -293,9 +294,7 @@ public class LocalChannel extends AbstractChannel {
peerLoop.execute(new Runnable() {
@Override
public void run() {
for (int i = 0; i < msgsCopy.length; i++) {
peer.inboundBuffer.add(msgsCopy[i]);
}
Collections.addAll(peer.inboundBuffer, msgsCopy);
finishPeerRead(peer, peerPipeline);
}
});
@ -350,7 +349,6 @@ public class LocalChannel extends AbstractChannel {
doBind(localAddress);
} catch (Throwable t) {
promise.setFailure(t);
pipeline().fireExceptionCaught(t);
close(voidPromise());
return;
}

View File

@ -210,8 +210,8 @@ public abstract class AbstractNioChannel extends AbstractChannel {
newT.setStackTrace(t.getStackTrace());
t = newT;
}
closeIfClosed();
promise.tryFailure(t);
closeIfClosed();
}
}

View File

@ -80,8 +80,8 @@ public abstract class AbstractOioChannel extends AbstractChannel {
newT.setStackTrace(t.getStackTrace());
t = newT;
}
closeIfClosed();
promise.setFailure(t);
closeIfClosed();
}
}
}