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 D0758200C69 for ; Sat, 6 May 2017 20:34:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C77E1160BAD; Sat, 6 May 2017 18:34:09 +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 E6402160B9F for ; Sat, 6 May 2017 20:34:08 +0200 (CEST) Received: (qmail 20067 invoked by uid 500); 6 May 2017 18:34:08 -0000 Mailing-List: contact dev-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 dev@hc.apache.org Received: (qmail 20054 invoked by uid 99); 6 May 2017 18:34:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 May 2017 18:34:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 85741C03A8 for ; Sat, 6 May 2017 18:34:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id iCXyPGnqiid9 for ; Sat, 6 May 2017 18:34:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 1EAC05F567 for ; Sat, 6 May 2017 18:34:06 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 79AD4E08BB for ; Sat, 6 May 2017 18:34:05 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 7CA7221DEC for ; Sat, 6 May 2017 18:34:04 +0000 (UTC) Date: Sat, 6 May 2017 18:34:04 +0000 (UTC) From: "Daniel Krawczyk (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (HTTPCORE-463) Async client does not respect IOReactor's connection timeout setting MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sat, 06 May 2017 18:34:10 -0000 [ https://issues.apache.org/jira/browse/HTTPCORE-463?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Daniel Krawczyk closed HTTPCORE-463. ------------------------------------ > Async client does not respect IOReactor's connection timeout setting > -------------------------------------------------------------------- > > Key: HTTPCORE-463 > URL: https://issues.apache.org/jira/browse/HTTPCORE-463 > Project: HttpComponents HttpCore > Issue Type: Bug > Affects Versions: 4.4.6 > Reporter: Daniel Krawczyk > Fix For: 4.4.7 > > > Hello, I've noticed an issue with the async client where connection timeout setting is not respected when configured for `IOReactor` object. > When I create the client like this: > {code} > CloseableHttpAsyncClient createAsyncClient() { > return HttpAsyncClientBuilder.create() > .setConnectionManager(connectionManager()) > .build(); > } > {code} > where connection manager is configured as follows: > {code} > private PoolingNHttpClientConnectionManager connectionManager() { > IOReactorConfig reactorConfig = IOReactorConfig.custom() > .setConnectTimeout(config.getConnectionTimeout()) // this doesn't work > .setSoTimeout(config.getSocketTimeout()) // this works > .setSelectInterval(config.getTimeoutCheckInterval()) > .setIoThreadCount(config.getNioThreads()) > .setTcpNoDelay(true) > .build(); > ConnectingIOReactor reactor = new DefaultConnectingIOReactor(reactorConfig, threadFactory()); > return new PoolingNHttpClientConnectionManager(reactor); > } > {code} > the `setConnectTimeout(...)` option is not respected. > After some longer time (this might be some system default? - 30 or 120 seconds, depends on the system I run the code) I get an exception thrown from a native method: > {code} > 11:27:02.223 [pool-2-thread-1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection request failed > java.net.ConnectException: Operation timed out > at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) > at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716) > at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:171) > at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:145) > at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) > at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194) > at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) > at java.lang.Thread.run(Thread.java:745) > {code} > On the other hand the socket timeout setting works as expected. > ... > After debugging this, I found a way to cope with that by adding a default request config on the client: > {code} > CloseableHttpAsyncClient createAsyncClient() { > return HttpAsyncClientBuilder.create() > .setConnectionManager(connectionManager()) > .setDefaultRequestConfig(requestConfig()) // this works > .build(); > } > private RequestConfig requestConfig() { > return RequestConfig.custom() > .setConnectTimeout(config.getConnectionTimeout()) // this works > .setSocketTimeout(config.getSocketTimeout()) // this works as well > .build(); > } > {code} > This way it works, I get an exception after specified time: > {code} > 11:05:37.267 [pool-2-thread-1] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection request failed > java.net.ConnectException: null > at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:168) > at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:584) > at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:851) > at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:183) > at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:210) > at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:155) > at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) > at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194) > at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) > at java.lang.Thread.run(Thread.java:745) > {code} > The test I performed looked something like this (groovy/spock): > {code} > def "test bare client"() { > given: > def client = asyncClientFactory.createAsyncClient() // creates client with some short connection timeout > client.start() > when: > HttpGet request = new HttpGet("http://10.0.0.0") // call some non-routable IP to trigger the connection timeout > def response = client.execute(request, null).get() > then: > def e = thrown(ExecutionException) > e.cause instanceof ConnectException > cleanup: > client.close() > } > {code} > Regards, > Daniel -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org