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 C09DE200C6F for ; Tue, 9 May 2017 22:02:56 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BF647160BD7; Tue, 9 May 2017 20:02:56 +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 5F022160BB6 for ; Tue, 9 May 2017 22:02:54 +0200 (CEST) Received: (qmail 85373 invoked by uid 500); 9 May 2017 20:02:53 -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 84981 invoked by uid 99); 9 May 2017 20:02:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 May 2017 20:02:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3EB7AE178B; Tue, 9 May 2017 20:02:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: olegk@apache.org To: commits@hc.apache.org Date: Tue, 09 May 2017 20:03:12 -0000 Message-Id: <0a546aaf701c45e3a7579b99637eea74@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [21/50] httpcomponents-core git commit: HTTPCORE-334: https request to a non-responsive but alive port results in a busy loop in one of I/O dispatch threads Contributed by Scott Stanton archived-at: Tue, 09 May 2017 20:02:56 -0000 HTTPCORE-334: https request to a non-responsive but alive port results in a busy loop in one of I/O dispatch threads Contributed by Scott Stanton git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.2.x@1448439 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/2668ef51 Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/2668ef51 Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/2668ef51 Branch: refs/heads/4.2.x Commit: 2668ef514e3282dbeefe1cc939c5e046fb9a8eb7 Parents: 5640ae9 Author: Oleg Kalnichevski Authored: Wed Feb 20 22:11:34 2013 +0000 Committer: Oleg Kalnichevski Committed: Wed Feb 20 22:11:34 2013 +0000 ---------------------------------------------------------------------- RELEASE_NOTES.txt | 4 + .../http/nio/reactor/ssl/SSLIOSession.java | 2 +- .../org/apache/http/HttpCoreNIOTestBase.java | 9 +- .../nio/integration/TestHttpsAsyncTimeout.java | 146 +++++++++++++++++++ 4 files changed, 158 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2668ef51/RELEASE_NOTES.txt ---------------------------------------------------------------------- diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 72dcf42..5026368 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,5 +1,9 @@ Changes since 4.2.3 +* [HTTPCORE-334] https request to a non-responsive but alive port results in a busy loop + in one of I/O dispatch threads. + Contributed by Scott Stanton + * [HTTPCORE-331] BasicFuture no longer executes notification callbacks inside a synchronized block. Contributed by Oleg Kalnichevski http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2668ef51/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java ---------------------------------------------------------------------- diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java index 2613b66..c579e14 100644 --- a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java +++ b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java @@ -310,7 +310,7 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces newMask = EventMask.READ_WRITE; break; case NEED_UNWRAP: - newMask = EventMask.READ | (this.appEventMask & EventMask.WRITE); + newMask = EventMask.READ; break; case NOT_HANDSHAKING: newMask = this.appEventMask; http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2668ef51/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java ---------------------------------------------------------------------- diff --git a/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java b/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java index 6777b38..3605c94 100644 --- a/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java +++ b/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java @@ -55,7 +55,6 @@ import org.junit.After; /** * Base class for all HttpCore NIO tests - * */ public abstract class HttpCoreNIOTestBase { @@ -74,6 +73,11 @@ public abstract class HttpCoreNIOTestBase { protected abstract NHttpConnectionFactory createClientConnectionFactory( HttpParams params) throws Exception; + protected NHttpConnectionFactory createClientSSLConnectionFactory( + HttpParams params) throws Exception { + return null; + } + public void initServer() throws Exception { this.serverParams = new SyncBasicHttpParams(); this.serverParams @@ -115,7 +119,8 @@ public abstract class HttpCoreNIOTestBase { public void initConnPool() throws Exception { this.connpool = new BasicNIOConnPool( this.client.getIoReactor(), - new BasicNIOConnFactory(createClientConnectionFactory(this.clientParams)), + new BasicNIOConnFactory(createClientConnectionFactory(this.clientParams), + createClientSSLConnectionFactory(this.clientParams)), this.clientParams); this.executor = new HttpAsyncRequester( this.clientHttpProc, http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2668ef51/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java ---------------------------------------------------------------------- diff --git a/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java b/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java new file mode 100644 index 0000000..e8daf1d --- /dev/null +++ b/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java @@ -0,0 +1,146 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.nio.integration; + +import org.apache.http.HttpCoreNIOTestBase; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.LoggingClientConnectionFactory; +import org.apache.http.LoggingSSLClientConnectionFactory; +import org.apache.http.SSLTestContexts; +import org.apache.http.concurrent.FutureCallback; +import org.apache.http.impl.nio.DefaultNHttpClientConnection; +import org.apache.http.impl.nio.DefaultNHttpServerConnection; +import org.apache.http.message.BasicHttpRequest; +import org.apache.http.nio.NHttpConnectionFactory; +import org.apache.http.nio.protocol.BasicAsyncRequestProducer; +import org.apache.http.nio.protocol.BasicAsyncResponseConsumer; +import org.apache.http.nio.protocol.HttpAsyncRequestExecutor; +import org.apache.http.params.CoreConnectionPNames; +import org.apache.http.params.HttpParams; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class TestHttpsAsyncTimeout extends HttpCoreNIOTestBase { + + private ServerSocket serverSocket; + + @Before + public void setUp() throws Exception { + initClient(); + initConnPool(); + } + + @After + public void tearDown() throws Exception { + serverSocket.close(); + shutDownClient(); + } + + @Override + protected NHttpConnectionFactory createServerConnectionFactory( + final HttpParams params) throws Exception { + return null; + } + + @Override + protected NHttpConnectionFactory createClientConnectionFactory( + final HttpParams params) throws Exception { + return new LoggingClientConnectionFactory(params); + } + + @Override + protected NHttpConnectionFactory createClientSSLConnectionFactory( + final HttpParams params) throws Exception { + + return new LoggingSSLClientConnectionFactory(SSLTestContexts.createClientSSLContext(), params); + } + + private InetSocketAddress start() throws Exception { + + HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor(); + this.client.start(clientHandler); + serverSocket = new ServerSocket(0); + return new InetSocketAddress(serverSocket.getInetAddress(), serverSocket.getLocalPort()); + } + + @Test + public void testHandshakeTimeout() throws Exception { + // This test creates a server socket and accepts the incoming + // socket connection without reading any data. The client should + // connect, be unable to progress through the handshake, and then + // time out when SO_TIMEOUT has elapsed. + + InetSocketAddress address = start(); + HttpHost target = new HttpHost("localhost", address.getPort(), "https"); + + final CountDownLatch latch = new CountDownLatch(1); + + FutureCallback callback = new FutureCallback() { + + public void cancelled() { + latch.countDown(); + } + + public void failed(final Exception ex) { + latch.countDown(); + } + + public void completed(final HttpResponse response) { + Assert.fail(); + } + + }; + + HttpRequest request = new BasicHttpRequest("GET", "/"); + HttpContext context = new BasicHttpContext(); + this.clientParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 2000); + this.executor.execute( + new BasicAsyncRequestProducer(target, request), + new BasicAsyncResponseConsumer(), + this.connpool, context, callback); + Socket accepted = serverSocket.accept(); + try { + Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); + } finally { + accepted.close(); + } + } + +}