461499 - ConnectionPool may leak connections.

Avoid that the complete event is notified before or concurrently with
the response success event.
This commit is contained in:
Simone Bordet 2015-03-26 11:32:32 +01:00
parent 7bc2d50bf7
commit 07d29fb1b3
2 changed files with 11 additions and 11 deletions

View File

@ -33,6 +33,7 @@ import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.CountingCallback;
@ -366,8 +367,7 @@ public abstract class HttpReceiver
{
// Mark atomically the response as completed, with respect
// to concurrency between response success and response failure.
boolean completed = exchange.responseComplete(null);
if (!completed)
if (!exchange.responseComplete(null))
return false;
responseState.set(ResponseState.IDLE);
@ -375,13 +375,6 @@ public abstract class HttpReceiver
// Reset to be ready for another response.
reset();
// Mark atomically the response as terminated, with
// respect to concurrency between request and response.
Result result = exchange.terminateResponse();
// Notify *after* resetting and terminating, because
// the notification may trigger another request/response,
// or the reset of the response in case of 100-Continue.
HttpResponse response = exchange.getResponse();
if (LOG.isDebugEnabled())
LOG.debug("Response success {}", response);
@ -389,6 +382,14 @@ public abstract class HttpReceiver
ResponseNotifier notifier = getHttpDestination().getResponseNotifier();
notifier.notifySuccess(listeners, response);
// Special case for 100 Continue that cannot
// be handled by the ContinueProtocolHandler.
if (exchange.getResponse().getStatus() == HttpStatus.CONTINUE_100)
return true;
// Mark atomically the response as terminated, with
// respect to concurrency between request and response.
Result result = exchange.terminateResponse();
terminateResponse(exchange, result);
return true;

View File

@ -303,8 +303,7 @@ public abstract class HttpSender implements AsyncContentProvider.Listener
{
// Mark atomically the request as completed, with respect
// to concurrency between request success and request failure.
boolean completed = exchange.requestComplete(null);
if (!completed)
if (!exchange.requestComplete(null))
return false;
requestState.set(RequestState.QUEUED);