You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/09 20:01:44 UTC
[18/50] httpcomponents-core git commit: HTTPCLIENT-1808: Fixing
potential overflow for connection TTL Contributed by Andrew Shore
HTTPCLIENT-1808: Fixing potential overflow for connection TTL
Contributed by Andrew Shore <shorea at amazon.com>
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1780648 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/e555fabb
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/e555fabb
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/e555fabb
Branch: refs/heads/4.4.x
Commit: e555fabb7a2f0458cbe1cce3d5d6983f200bd018
Parents: 10331fe
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sat Jan 28 09:50:13 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sat Jan 28 09:50:13 2017 +0000
----------------------------------------------------------------------
httpcore/src/main/java/org/apache/http/pool/PoolEntry.java | 8 +++++---
.../src/test/java/org/apache/http/pool/TestPoolEntry.java | 6 ++++++
2 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e555fabb/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java b/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
index 31b8ee2..dad5139 100644
--- a/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
+++ b/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
@@ -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;
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e555fabb/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
----------------------------------------------------------------------
diff --git a/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java b/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
index 927f160..6bad38e 100644
--- a/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
+++ b/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
@@ -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);
+ }
+
}