hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1659667 - in /httpcomponents/httpasyncclient/trunk: RELEASE_NOTES.txt httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolEntry.java
Date Fri, 13 Feb 2015 20:35:46 GMT
Author: olegk
Date: Fri Feb 13 20:35:45 2015
New Revision: 1659667

URL: http://svn.apache.org/r1659667
Log:
HTTPASYNC-88: persistent connections can time out while kept alive in the pool causing unexpected
SocketTimeoutException

Modified:
    httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolEntry.java

Modified: httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt?rev=1659667&r1=1659666&r2=1659667&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt Fri Feb 13 20:35:45 2015
@@ -29,6 +29,10 @@ subsequent requests
 Release 4.0.2
 -------------------
 
+* [HTTPASYNC-88] persistent connections can time out while kept alive in the pool
+  causing unexpected SocketTimeoutException
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPASYNC-86]: fixed a race condition upon connection lease from the connection pool:

   in very rare  circumstances the main execution thread can get jammed for so long 
   that the I/O dispatch thread succeeds in completing the request and releasing the connection


Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java?rev=1659667&r1=1659666&r2=1659667&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java
Fri Feb 13 20:35:45 2015
@@ -32,6 +32,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.conn.ManagedNHttpClientConnection;
 import org.apache.http.nio.pool.AbstractNIOConnPool;
 import org.apache.http.nio.pool.NIOConnFactory;
@@ -59,7 +60,22 @@ class CPool extends AbstractNIOConnPool<
 
     @Override
     protected CPoolEntry createEntry(final HttpRoute route, final ManagedNHttpClientConnection
conn) {
-        return new CPoolEntry(this.log, conn.getId(), route, conn, this.timeToLive, this.tunit);
+        final CPoolEntry entry =  new CPoolEntry(this.log, conn.getId(), route, conn, this.timeToLive,
this.tunit);
+        entry.setSocketTimeout(conn.getSocketTimeout());
+        return entry;
+    }
+
+    @Override
+    protected void onLease(final CPoolEntry entry) {
+        final NHttpClientConnection conn = entry.getConnection();
+        conn.setSocketTimeout(entry.getSocketTimeout());
+    }
+
+    @Override
+    protected void onRelease(final CPoolEntry entry) {
+        final NHttpClientConnection conn = entry.getConnection();
+        entry.setSocketTimeout(conn.getSocketTimeout());
+        conn.setSocketTimeout(0);
     }
 
 }

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolEntry.java?rev=1659667&r1=1659666&r2=1659667&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolEntry.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolEntry.java
Fri Feb 13 20:35:45 2015
@@ -40,6 +40,7 @@ import org.apache.http.pool.PoolEntry;
 class CPoolEntry extends PoolEntry<HttpRoute, ManagedNHttpClientConnection> {
 
     private final Log log;
+    private volatile int socketTimeout;
     private volatile boolean routeComplete;
 
     public CPoolEntry(
@@ -60,6 +61,14 @@ class CPoolEntry extends PoolEntry<HttpR
         this.routeComplete = true;
     }
 
+    public int getSocketTimeout() {
+        return this.socketTimeout;
+    }
+
+    public void setSocketTimeout(final int socketTimeout) {
+        this.socketTimeout = socketTimeout;
+    }
+
     public void closeConnection() throws IOException {
         final ManagedNHttpClientConnection conn = getConnection();
         conn.close();



Mime
View raw message