Fail unflushed writes with ClosedChannelException

... instead of cryptic exception message.
This commit is contained in:
Trustin Lee 2013-07-17 21:25:51 +09:00
parent 5f235eafc3
commit 88cbdb50d2
2 changed files with 4 additions and 8 deletions

View File

@ -511,7 +511,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
outboundBuffer.fail(CLOSED_CHANNEL_EXCEPTION);
}
outboundBuffer.clearUnflushed();
outboundBuffer.clearUnflushed(CLOSED_CHANNEL_EXCEPTION);
if (wasActive && !isActive()) {
invokeLater(new Runnable() {

View File

@ -211,7 +211,7 @@ final class ChannelOutboundBuffer {
return head == tail;
}
void clearUnflushed() {
void clearUnflushed(Throwable cause) {
MessageList unflushed = unflushedMessageList;
if (unflushed == null) {
return;
@ -221,17 +221,13 @@ final class ChannelOutboundBuffer {
Object[] messages = unflushed.messages();
ChannelPromise[] promises = unflushed.promises();
final int size = unflushed.size();
Throwable flushAborted = null;
try {
for (int i = 0; i < size; i++) {
ReferenceCountUtil.release(messages[i]);
ChannelPromise p = promises[i];
if (!(p instanceof VoidChannelPromise)) {
if (flushAborted == null) {
flushAborted = new ChannelException("write() aborted without flush()");
}
if (!p.tryFailure(flushAborted)) {
logger.warn("Promise done already: {} - new exception is:", p, flushAborted);
if (!p.tryFailure(cause)) {
logger.warn("Promise done already: {} - new exception is:", p, cause);
}
}
}