hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1299037 - /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
Date Fri, 09 Mar 2012 20:34:33 GMT
Author: olegk
Date: Fri Mar  9 20:34:33 2012
New Revision: 1299037

URL: http://svn.apache.org/viewvc?rev=1299037&view=rev
Log:
Added defensive code for a fringe case when the connection leased from the pool gets immediately
closed by the opposite endpoint

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1299037&r1=1299036&r2=1299037&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
Fri Mar  9 20:34:33 2012
@@ -34,6 +34,7 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.logging.Log;
+import org.apache.http.ConnectionClosedException;
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
@@ -124,6 +125,7 @@ class DefaultAsyncRequestDirector<T> imp
     private int redirectCount;
     private ByteBuffer tmpbuf;
     private boolean requestContentProduced;
+    private boolean requestSent;
     private int execCount;
 
     public DefaultAsyncRequestDirector(
@@ -275,6 +277,7 @@ class DefaultAsyncRequestDirector<T> imp
     }
 
     public void requestCompleted(final HttpContext context) {
+        this.requestSent = true;
         this.requestProducer.requestCompleted(context);
     }
 
@@ -283,6 +286,7 @@ class DefaultAsyncRequestDirector<T> imp
     }
 
     public void resetRequest() throws IOException {
+        this.requestSent = false;
         this.requestProducer.resetRequest();
     }
 
@@ -378,6 +382,9 @@ class DefaultAsyncRequestDirector<T> imp
 
     public synchronized void failed(final Exception ex) {
         try {
+            if (!this.requestSent) {
+                this.requestProducer.failed(ex);
+            }
             this.responseConsumer.failed(ex);
         } finally {
             try {
@@ -510,6 +517,9 @@ class DefaultAsyncRequestDirector<T> imp
             this.managedConn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER,
this);
             this.managedConn.requestOutput();
             this.routeEstablished = route.equals(conn.getRoute());
+            if (!this.managedConn.isOpen()) {
+                throw new ConnectionClosedException("Connection closed");
+            }
         } catch (IOException ex) {
             failed(ex);
         } catch (RuntimeException runex) {



Mime
View raw message