Improved error reporting in case of a write failure.

This commit is contained in:
Simone Bordet 2012-06-04 15:39:01 +02:00
parent 1bfb7df771
commit f0c2fd2474
1 changed files with 12 additions and 12 deletions

View File

@ -97,7 +97,7 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
private final AtomicInteger lastStreamId = new AtomicInteger(); private final AtomicInteger lastStreamId = new AtomicInteger();
private final FlowControlStrategy flowControlStrategy; private final FlowControlStrategy flowControlStrategy;
private boolean flushing; private boolean flushing;
private boolean failed = false; private Throwable failure;
public StandardSession(short version, ByteBufferPool bufferPool, Executor threadPool, ScheduledExecutorService scheduler, public StandardSession(short version, ByteBufferPool bufferPool, Executor threadPool, ScheduledExecutorService scheduler,
Controller<FrameBytes> controller, IdleListener idleListener, int initialStreamId, SessionFrameListener listener, Controller<FrameBytes> controller, IdleListener idleListener, int initialStreamId, SessionFrameListener listener,
@ -870,11 +870,11 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
private void append(FrameBytes frameBytes) private void append(FrameBytes frameBytes)
{ {
boolean fail; Throwable failure;
synchronized (queue) synchronized (queue)
{ {
fail = failed; failure = this.failure;
if (!fail) if (failure == null)
{ {
int index = queue.size(); int index = queue.size();
while (index > 0) while (index > 0)
@ -888,17 +888,17 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
} }
} }
if (fail) if (failure != null)
frameBytes.fail(new SPDYException("Session failed")); frameBytes.fail(new SPDYException(failure));
} }
private void prepend(FrameBytes frameBytes) private void prepend(FrameBytes frameBytes)
{ {
boolean fail; Throwable failure;
synchronized (queue) synchronized (queue)
{ {
fail = failed; failure = this.failure;
if (!fail) if (failure == null)
{ {
int index = 0; int index = 0;
while (index < queue.size()) while (index < queue.size())
@ -912,8 +912,8 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
} }
} }
if (fail) if (failure != null)
frameBytes.fail(new SPDYException("Session failed")); frameBytes.fail(new SPDYException(failure));
} }
@Override @Override
@ -935,7 +935,7 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
synchronized (queue) synchronized (queue)
{ {
failed = true; failure = x;
String logMessage = String.format("Failed write of %s, failing all %d frame(s) in queue",frameBytes,queue.size()); String logMessage = String.format("Failed write of %s, failing all %d frame(s) in queue",frameBytes,queue.size());
logger.debug(logMessage,x); logger.debug(logMessage,x);
frameBytesToFail.addAll(queue); frameBytesToFail.addAll(queue);