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/01/28 09:50:39 UTC
svn commit: r1780649 - in /httpcomponents/httpcore/trunk/httpcore5/src:
main/java/org/apache/hc/core5/pool/PoolEntry.java
test/java/org/apache/hc/core5/pool/TestPoolEntry.java
Author: olegk
Date: Sat Jan 28 09:50:39 2017
New Revision: 1780649
URL: http://svn.apache.org/viewvc?rev=1780649&view=rev
Log:
HTTPCLIENT-1808: Fixing potential overflow for connection TTL
Contributed by Andrew Shore <shorea at amazon.com>
Modified:
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java?rev=1780649&r1=1780648&r2=1780649&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java Sat Jan 28 09:50:39 2017
@@ -121,7 +121,13 @@ public final class PoolEntry<T, C extend
if (this.connRef.compareAndSet(null, conn)) {
this.created = currentTimeMillis();
this.updated = this.created;
- this.validityDeadline = this.timeToLive > 0 ? System.currentTimeMillis() + this.timeToLive : Long.MAX_VALUE;
+ if (this.timeToLive > 0) {
+ final long deadline = System.currentTimeMillis() + this.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;
+ }
this.expiry = this.validityDeadline;
this.state = null;
} else {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java?rev=1780649&r1=1780648&r2=1780649&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java Sat Jan 28 09:50:39 2017
@@ -87,4 +87,17 @@ public class TestPoolEntry {
Assert.assertEquals(entry2.getUpdated() + 50L, entry2.getExpiry());
}
+ @Test(expected=IllegalArgumentException.class)
+ public void testInvalidExpiry() throws Exception {
+ final PoolEntry<String, HttpConnection> entry = new PoolEntry<>("route1", 0L, TimeUnit.MILLISECONDS);
+ entry.updateExpiry(50L, null);
+ }
+
+ @Test
+ public void testExpiryDoesNotOverflow() {
+ final PoolEntry<String, HttpConnection> entry = new PoolEntry<>("route1", Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ entry.assignConnection(Mockito.mock(HttpConnection.class));
+ Assert.assertEquals(Long.MAX_VALUE, entry.getValidityDeadline());
+ }
+
}