hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1780648 - in /httpcomponents/httpcore/branches/4.4.x/httpcore/src: main/java/org/apache/http/pool/PoolEntry.java test/java/org/apache/http/pool/TestPoolEntry.java
Date Sat, 28 Jan 2017 09:50:13 GMT
Author: olegk
Date: Sat Jan 28 09:50:13 2017
New Revision: 1780648

URL: http://svn.apache.org/viewvc?rev=1780648&view=rev
Log:
HTTPCLIENT-1808: Fixing potential overflow for connection TTL
Contributed by Andrew Shore <shorea at amazon.com>

Modified:
    httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
    httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java

Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java?rev=1780648&r1=1780647&r2=1780648&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
(original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
Sat Jan 28 09:50:13 2017
@@ -26,12 +26,12 @@
  */
 package org.apache.http.pool;
 
-import java.util.concurrent.TimeUnit;
-
 import org.apache.http.annotation.Contract;
 import org.apache.http.annotation.ThreadingBehavior;
 import org.apache.http.util.Args;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * Pool entry containing a pool connection object along with its route.
  * <p>
@@ -85,7 +85,9 @@ public abstract class PoolEntry<T, C> {
         this.created = System.currentTimeMillis();
         this.updated = this.created;
         if (timeToLive > 0) {
-            this.validityDeadline = this.created + tunit.toMillis(timeToLive);
+            final long deadline = this.created + tunit.toMillis(timeToLive);
+            // If the above overflows then default to Long.MAX_VALUE
+            this.validityDeadline = deadline > 0 ? deadline : Long.MAX_VALUE;
         } else {
             this.validityDeadline = Long.MAX_VALUE;
         }

Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java?rev=1780648&r1=1780647&r2=1780648&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
(original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
Sat Jan 28 09:50:13 2017
@@ -122,4 +122,10 @@ public class TestPoolEntry {
         entry1.updateExpiry(50L, null);
     }
 
+    @Test
+    public void testExpiryDoesNotOverflow() {
+        final MockPoolEntry entry = new MockPoolEntry("route1", Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+        Assert.assertEquals(entry.getValidityDeadline(), Long.MAX_VALUE);
+    }
+
 }



Mime
View raw message