Return-Path: X-Original-To: apmail-hc-dev-archive@www.apache.org Delivered-To: apmail-hc-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09FAC176E7 for ; Fri, 13 Feb 2015 14:57:15 +0000 (UTC) Received: (qmail 18043 invoked by uid 500); 13 Feb 2015 14:57:12 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 17998 invoked by uid 500); 13 Feb 2015 14:57:12 -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 17987 invoked by uid 99); 13 Feb 2015 14:57:11 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Feb 2015 14:57:11 +0000 Date: Fri, 13 Feb 2015 14:57:11 +0000 (UTC) From: "Changgeng Li (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HTTPASYNC-88) Race condition caused SocketTimeoutException MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HTTPASYNC-88?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14320198#comment-14320198 ] Changgeng Li commented on HTTPASYNC-88: --------------------------------------- When this happened we found the request has not yet been sent. > Race condition caused SocketTimeoutException > -------------------------------------------- > > Key: HTTPASYNC-88 > URL: https://issues.apache.org/jira/browse/HTTPASYNC-88 > Project: HttpComponents HttpAsyncClient > Issue Type: Bug > Affects Versions: 4.0.2 > Environment: Linux > Jdk1.6.0_45 > Reporter: Changgeng Li > > This issue can be reproduced by following test case. > {code} > import org.apache.http.client.methods.HttpGet; > import org.apache.http.client.protocol.HttpClientContext; > import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; > import org.apache.http.impl.nio.client.HttpAsyncClients; > import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; > import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; > import org.apache.http.impl.nio.reactor.IOReactorConfig; > import org.apache.http.nio.reactor.IOReactorException; > import org.junit.Test; > import java.util.concurrent.ExecutionException; > import java.util.concurrent.Future; > import java.util.concurrent.TimeUnit; > import java.util.concurrent.TimeoutException; > public class AsyncClientTest { > @Test > public void testTimeout() > throws InterruptedException, ExecutionException, TimeoutException, IOReactorException { > PoolingNHttpClientConnectionManager manager = new PoolingNHttpClientConnectionManager( > new DefaultConnectingIOReactor(buildConfig())); > manager.setDefaultMaxPerRoute(10); > manager.setMaxTotal(10); > CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setConnectionManager(manager).build(); > HttpGet httpget = new HttpGet("http://localhost:8080/"); > HttpClientContext localContext = HttpClientContext.create(); > httpclient.start(); > // Pass local context as a parameter > for (int j = 0; j < 1000; j++) { > for (int i = 0; i < 5; i++) { > Future future = httpclient.execute(httpget, localContext, null); > HttpResponse response = future.get(5000L, TimeUnit.MILLISECONDS); > System.out.println("Response: " + response.getStatusLine()); > Thread.sleep(180 + i * 10); > } > } > } > private IOReactorConfig buildConfig() { > final IOReactorConfig.Builder ioReactorConfigBuilder = IOReactorConfig.custom(); > ioReactorConfigBuilder.setConnectTimeout(100); > ioReactorConfigBuilder.setInterestOpQueued(false); > ioReactorConfigBuilder.setIoThreadCount(3); > ioReactorConfigBuilder.setSelectInterval(100); > ioReactorConfigBuilder.setShutdownGracePeriod(500L); > ioReactorConfigBuilder.setSoKeepAlive(true); > ioReactorConfigBuilder.setSoLinger(-1); > ioReactorConfigBuilder.setSoReuseAddress(false); > ioReactorConfigBuilder.setSoTimeout(200); > ioReactorConfigBuilder.setTcpNoDelay(false); > return ioReactorConfigBuilder.build(); > } > } > {code} > It needs a standalone webserver, for me I just start my tomcat. > Changing the sleep time to > {code} > Thread.sleep(181 + i * 10); > {code} > would make the reproduce chance much lower. > The exception I normally got is: > {code} > java.util.concurrent.ExecutionException: java.net.SocketTimeoutException > at org.apache.http.concurrent.BasicFuture.getResult(BasicFuture.java:68) > at org.apache.http.concurrent.BasicFuture.get(BasicFuture.java:94) > at org.apache.http.AsyncClientTest.testTimeout(AsyncClientTest.java:36) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) > at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) > at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) > at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) > at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) > at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) > at org.junit.runners.ParentRunner.run(ParentRunner.java:236) > at org.junit.runner.JUnitCore.run(JUnitCore.java:157) > at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) > at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) > at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) > Caused by: java.net.SocketTimeoutException > at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.timeout(HttpAsyncRequestExecutor.java:286) > at org.apache.http.impl.nio.client.LoggingAsyncRequestExecutor.timeout(LoggingAsyncRequestExecutor.java:121) > at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:85) > at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:37) > at org.apache.http.impl.nio.reactor.AbstractIODispatch.timeout(AbstractIODispatch.java:172) > at org.apache.http.impl.nio.reactor.BaseIOReactor.sessionTimedOut(BaseIOReactor.java:255) > at org.apache.http.impl.nio.reactor.AbstractIOReactor.timeoutCheck(AbstractIOReactor.java:493) > at org.apache.http.impl.nio.reactor.BaseIOReactor.validate(BaseIOReactor.java:205) > at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:281) > at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105) > at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:584) > at java.lang.Thread.run(Thread.java:662) > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org