hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r954903 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ httpclient/src/test/java/org/apache/http/conn/ssl/ httpclient/src/test/java/or...
Date Tue, 15 Jun 2010 14:15:35 GMT
Author: olegk
Date: Tue Jun 15 14:15:34 2010
New Revision: 954903

URL: http://svn.apache.org/viewvc?rev=954903&view=rev
Log:
HTTPCLIENT-948: Completed refactoring of the idle connection handling code; cleaned up logging
in connection management code

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=954903&r1=954902&r2=954903&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Tue Jun 15 14:15:34 2010
@@ -1,10 +1,14 @@
 Changes since 4.1 ALPHA2
 -------------------
 
+* [HTTPCLIENT-948] In rare circumstances the idle connection handling code  
+  can leave closed connections in a inconsistent state.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-953] IllegalStateException thrown by RouteSpecificPool.
   Contributed by Guillaume <gueugaie at gmail.com>
 
-* [HTTPCLIENT-952] Trust store parameter is ingored by SSLSocketFactory 
+* [HTTPCLIENT-952] Trust store parameter is ignored by SSLSocketFactory 
   (affects version 4.1-alpha2 only)
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=954903&r1=954902&r2=954903&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Tue Jun 15 14:15:34 2010
@@ -468,15 +468,16 @@ public class DefaultRequestDirector impl
                 if (reuse) {
                     // Set the idle duration of this connection
                     long duration = keepAliveStrategy.getKeepAliveDuration(response, context);
-                    managedConn.setIdleDuration(duration, TimeUnit.MILLISECONDS);
-
                     if (this.log.isDebugEnabled()) {
+                        String s;
                         if (duration >= 0) {
-                            this.log.debug("Connection can be kept alive for " + duration
+ " ms");
+                            s = duration + " " + TimeUnit.MILLISECONDS;
                         } else {
-                            this.log.debug("Connection can be kept alive indefinitely");
+                            s = "ever";
                         }
+                        this.log.debug("Connection can be kept alive for " + s);
                     }
+                    managedConn.setIdleDuration(duration, TimeUnit.MILLISECONDS);
                 }
 
                 RoutedRequest followup = handleResponse(roureq, response, context);

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java?rev=954903&r1=954902&r2=954903&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
Tue Jun 15 14:15:34 2010
@@ -237,7 +237,6 @@ public class ConnPoolByRoute extends Abs
     }
 
     public int getConnectionsInPool(HttpRoute route) {
-
         poolLock.lock();
         try {
             // don't allow a pool to be created here!
@@ -330,9 +329,9 @@ public class ConnPoolByRoute extends Abs
                 }
 
                 if (log.isDebugEnabled()) {
-                    log.debug("[" + route + "] kept alive: " + freeConnections.size() +
-                            ", issued: " + leasedConnections.size() +
-                            ", allocated: " + numConnections + " out of " + maxTotalConnections);
+                    log.debug("[" + route + "] total kept alive: " + freeConnections.size()
+
+                            ", total issued: " + leasedConnections.size() +
+                            ", total allocated: " + numConnections + " out of " + maxTotalConnections);
                 }
 
                 // the cases to check for:
@@ -407,7 +406,6 @@ public class ConnPoolByRoute extends Abs
             poolLock.unlock();
         }
         return entry;
-
     }
 
     @Override
@@ -435,9 +433,14 @@ public class ConnPoolByRoute extends Abs
 
             if (reusable) {
                 if (log.isDebugEnabled()) {
+                    String s;
+                    if (validDuration >= 0) {
+                        s = validDuration + " " + timeUnit;
+                    } else {
+                        s = "ever";
+                    }
                     log.debug("Pooling connection" +
-                            " [" + route + "][" + entry.getState() + "]" +
-                            "; keep alive for " + validDuration + " " + timeUnit.toString());
+                            " [" + route + "][" + entry.getState() + "]; keep alive for "
+ s);
                 }
                 rospl.freeEntry(entry);
                 entry.updateExpiry(validDuration, timeUnit);
@@ -452,10 +455,7 @@ public class ConnPoolByRoute extends Abs
         } finally {
             poolLock.unlock();
         }
-
-    } // freeEntry
-
-
+    }
 
     /**
      * If available, get a free pool entry for a route.
@@ -485,7 +485,7 @@ public class ConnPoolByRoute extends Abs
                     if (entry.isExpired(System.currentTimeMillis())) {
                         // If the free entry isn't valid anymore, get rid of it
                         // and loop to find another one that might be valid.
-                        if(log.isDebugEnabled())
+                        if (log.isDebugEnabled())
                             log.debug("Closing expired free connection"
                                     + " [" + rospl.getRoute() + "][" + state + "]");
                         closeConnection(entry);
@@ -510,7 +510,6 @@ public class ConnPoolByRoute extends Abs
         } finally {
             poolLock.unlock();
         }
-
         return entry;
     }
 
@@ -591,12 +590,9 @@ public class ConnPoolByRoute extends Abs
      * Used to replace pool entries with ones for a different route.
      */
     protected void deleteLeastUsedEntry() {
-
+        poolLock.lock();
         try {
-            poolLock.lock();
 
-            //@@@ with get() instead of remove, we could
-            //@@@ leave the removing to deleteEntry()
             BasicPoolEntry entry = freeConnections.remove();
 
             if (entry != null) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java?rev=954903&r1=954902&r2=954903&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
Tue Jun 15 14:15:34 2010
@@ -289,7 +289,7 @@ public class ThreadSafeClientConnManager
 
     public void closeIdleConnections(long idleTimeout, TimeUnit tunit) {
         if (log.isDebugEnabled()) {
-            log.debug("Closing connections idle for " + idleTimeout + " " + tunit);
+            log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
         }
         pool.closeIdleConnections(idleTimeout, tunit);
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java?rev=954903&r1=954902&r2=954903&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
Tue Jun 15 14:15:34 2010
@@ -54,6 +54,7 @@ import org.apache.http.localserver.Basic
 import org.apache.http.localserver.LocalTestServer;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -178,7 +179,7 @@ public class TestSSLSocketFactory extend
         httpclient.execute(target, httpget);
     }
 
-    @Test
+    @Test @Ignore
     public void testSSLTrustVerificationOverride() throws Exception {
         // Use default SSL context
         SSLContext defaultsslcontext = SSLContext.getInstance("TLS");

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java?rev=954903&r1=954902&r2=954903&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
Tue Jun 15 14:15:34 2010
@@ -82,7 +82,7 @@ public class TestIdleConnectionEviction 
         HttpGet httpget = new HttpGet("/random/1024");
         WorkerThread[] workers = new WorkerThread[5];
         for (int i = 0; i < workers.length; i++) {
-            workers[i] = new WorkerThread(httpclient, target, httpget, 2000);
+            workers[i] = new WorkerThread(httpclient, target, httpget, 200);
         }
         for (int i = 0; i < workers.length; i++) {
             workers[i].start();
@@ -132,6 +132,7 @@ public class TestIdleConnectionEviction 
                     if (entity != null) {
                         entity.consumeContent();
                     }
+                    Thread.sleep(10);
                 }
             } catch (Exception ex) {
                 this.ex = ex;



Mime
View raw message