[#1501] Fix NPE correctly which could accour if ChannelOutboundBuffer.fail(..) triggered another call to ChannelOutboundBuffer.fail(...)

This commit is contained in:
Norman Maurer 2013-07-02 09:58:41 +02:00
parent 8dfbcbda29
commit 5437835832

View File

@ -41,6 +41,7 @@ final class ChannelOutboundBuffer {
private int head; private int head;
private int tail; private int tail;
private boolean inFail;
private final AbstractChannel channel; private final AbstractChannel channel;
private int pendingOutboundBytes; private int pendingOutboundBytes;
@ -213,6 +214,15 @@ final class ChannelOutboundBuffer {
} }
void fail(Throwable cause) { void fail(Throwable cause) {
// We need to check if we already process the fail here as the notification of the future may trigger some
// other event which will also call ChannelOutboundBuffer and so set currentMessage and currentPromise to
// null.
// See https://github.com/netty/netty/issues/1501
if (inFail) {
return;
}
try {
inFail = true;
if (currentPromise == null) { if (currentPromise == null) {
if (!next()) { if (!next()) {
return; return;
@ -222,13 +232,6 @@ final class ChannelOutboundBuffer {
do { do {
if (!(currentPromise instanceof VoidChannelPromise) && !currentPromise.tryFailure(cause)) { if (!(currentPromise instanceof VoidChannelPromise) && !currentPromise.tryFailure(cause)) {
logger.warn("Promise done already:", cause); logger.warn("Promise done already:", cause);
} else {
// We need to check for next here as the notification of the future may trigger some other event
// which will also call ChannelOutboundBuffer and so set currentMessage and currentPromise to null.
// See https://github.com/netty/netty/issues/1501
if (!next()) {
return;
}
} }
// Release all failed messages. // Release all failed messages.
@ -241,5 +244,8 @@ final class ChannelOutboundBuffer {
currentMessages.recycle(); currentMessages.recycle();
} }
} while(next()); } while(next());
} finally {
inFail = false;
}
} }
} }