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 e307979a0d
commit d7f9b1ee76
4 changed files with 7 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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