HTTP client: fixed bug in case of connection failure:

requests may have stayed queued and never notified of a connection failure
if their number exceeded the max connection per address value.
This commit is contained in:
Simone Bordet 2012-10-26 13:21:32 +02:00
parent 58e8ff8fbf
commit b0306adf8d
1 changed files with 16 additions and 17 deletions

View File

@ -189,16 +189,7 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
@Override
public void run()
{
RequestPair pair = requests.poll();
if (pair != null)
{
Request request = pair.request;
requestNotifier.notifyFailure(request, x);
Response.Listener listener = pair.listener;
HttpResponse response = new HttpResponse(request, listener);
responseNotifier.notifyFailure(listener, response, x);
responseNotifier.notifyComplete(listener, new Result(request, x, response, x));
}
drain(x);
}
});
}
@ -209,6 +200,20 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
}
}
private void drain(Throwable x)
{
RequestPair pair;
while ((pair = requests.poll()) != null)
{
Request request = pair.request;
requestNotifier.notifyFailure(request, x);
Response.Listener listener = pair.listener;
HttpResponse response = new HttpResponse(request, listener);
responseNotifier.notifyFailure(listener, response, x);
responseNotifier.notifyComplete(listener, new Result(request, x, response, x));
}
}
/**
* <p>Processes a new connection making it idle or active depending on whether requests are waiting to be sent.</p>
* <p>A new connection is created when a request needs to be executed; it is possible that the request that
@ -319,13 +324,7 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
connection.close();
activeConnections.clear();
AsynchronousCloseException failure = new AsynchronousCloseException();
RequestPair pair;
while ((pair = requests.poll()) != null)
{
requestNotifier.notifyFailure(pair.request, failure);
responseNotifier.notifyComplete(pair.listener, new Result(pair.request, failure, null));
}
drain(new AsynchronousCloseException());
connectionCount.set(0);