Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BCB54200C0A for ; Sat, 28 Jan 2017 10:50:41 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id BB503160B51; Sat, 28 Jan 2017 09:50:41 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 10330160B35 for ; Sat, 28 Jan 2017 10:50:40 +0100 (CET) Received: (qmail 34143 invoked by uid 500); 28 Jan 2017 09:50:40 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 34133 invoked by uid 99); 28 Jan 2017 09:50:40 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Jan 2017 09:50:40 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id AC36D3A05B5 for ; Sat, 28 Jan 2017 09:50:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Sat, 28 Jan 2017 09:50:39 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170128095039.AC36D3A05B5@svn01-us-west.apache.org> archived-at: Sat, 28 Jan 2017 09:50:41 -0000 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 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 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 entry = new PoolEntry<>("route1", 0L, TimeUnit.MILLISECONDS); + entry.updateExpiry(50L, null); + } + + @Test + public void testExpiryDoesNotOverflow() { + final PoolEntry entry = new PoolEntry<>("route1", Long.MAX_VALUE, TimeUnit.MILLISECONDS); + entry.assignConnection(Mockito.mock(HttpConnection.class)); + Assert.assertEquals(Long.MAX_VALUE, entry.getValidityDeadline()); + } + }