hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Li <fancye...@gmail.com>
Subject Re: I have set read time out but thread hang on socketRead0
Date Mon, 21 Apr 2014 10:13:01 GMT
anyone could help?

On Wed, Apr 16, 2014 at 9:49 AM, Li Li <fancyerii@gmail.com> wrote:
> http://stackoverflow.com/questions/15874834/httpclient-hangs-on-socketread0-with-successfully-executed-method
>
> I have all the timeouts setup just fine but I found out we have on url
> that does http chunking but sends no results(works fine in chrome, but
> in http client it hangs forever even with the timeout set). Luckily I
> own the server and just return some garbage and it no longer hangs.
> This seems like a very unique bug in that http client does not handle
> some kind of empty chunking case well(though I could be way off)....I
> just know it hangs every time on that same url with empty data and
> that url is http chunking csv download back to our http client.
>
> is this reason causing hang?
>
> On Mon, Apr 14, 2014 at 10:17 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
>> On Mon, 2014-04-14 at 17:21 +0800, Li Li wrote:
>>> I am using http client 4.3. I use PoolingHttpClientConnectionManager
>>> with many threads.
>>> but I found one thread hangs on socketRead0(other thread is correct)
>>>
>>> netstat -anotp|grep 5872
>>> (Not all processes could be identified, non-owned process info
>>>  will not be shown, you would have to be root to see it all.)
>>> tcp        0      0 192.168.11.181:35251        192.168.11.169:61616
>>>      ESTABLISHED 5872/java           off (0.00/0/0)
>>> tcp        0      0 192.168.11.181:35252        192.168.11.169:61616
>>>      ESTABLISHED 5872/java           off (0.00/0/0)
>>> tcp        0      0 49.4.132.244:56035          221.204.231.139:80
>>>      ESTABLISHED 5872/java           off (0.00/0/0)
>>> tcp        0      0 192.168.11.181:41935        192.168.11.151:2181
>>>      ESTABLISHED 5872/java           off (0.00/0/0)
>>>
>>> java stack:
>>> "Thread-51" prio=10 tid=0x00007f7dfc20d800 nid=0x1846 runnable
>>> [0x00007f7d5c5c4000]
>>>    java.lang.Thread.State: RUNNABLE
>>>         at java.net.SocketInputStream.socketRead0(Native Method)
>>>         at java.net.SocketInputStream.read(SocketInputStream.java:152)
>>>         at java.net.SocketInputStream.read(SocketInputStream.java:122)
>>>         at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136)
>>>         at org.apache.http.impl.io.SessionInputBufferImpl.read(SessionInputBufferImpl.java:195)
>>>         at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
>>>         at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:200)
>>>         at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:103)
>>>         at org.apache.http.impl.execchain.ResponseEntityWrapper.streamClosed(ResponseEntityWrapper.java:120)
>>>         at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:227)
>>>         at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:174)
>>>         at org.apache.http.util.EntityUtils.consume(EntityUtils.java:88)
>>>         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222)
>>>         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160)
>>>         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:136)
>>>         at com.founder.httpclientfetcher.HttpClientFetcher.httpGet(HttpClientFetcher.java:464)
>>>
>>>  I am using 4.3.1
>>> <dependency>
>>> <groupId>org.apache.httpcomponents</groupId>
>>> <artifactId>httpclient</artifactId>
>>> <version>4.3.1</version>
>>> </dependency>
>>>
>>> my codes:
>>> defaultRequestConfig = RequestConfig
>>>     .custom()
>>>     .setCookieSpec(CookieSpecs.BEST_MATCH)
>>>     .setExpectContinueEnabled(true)
>>>
>>>     .setConnectTimeout(this.getConnectTimeout())
>>>     .setConnectionRequestTimeout(this.getConnectionRequestTimeout())
>>>     .setSocketTimeout(this.getReadTimeout()).build();
>>>
>>> HttpClientBuilder builder = HttpClients.custom();
>>>
>>> ConnectionKeepAliveStrategy myStrategy = null;
>>> HttpClientConnectionManager connManager = null;
>>>
>>> Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
>>>     .<ConnectionSocketFactory> create()
>>>     .register("http",
>>>     PlainConnectionSocketFactory.getSocketFactory())
>>>     .register("https",
>>>     SSLConnectionSocketFactory.getSocketFactory())
>>>     .build();
>>> connManager = new PoolingHttpClientConnectionManager(
>>> socketFactoryRegistry, null, new DNSResolverWithCache(
>>> dnsCache));
>>>
>>> ((PoolingHttpClientConnectionManager) connManager).setMaxTotal(this
>>>     .getMaxTotalConnection());
>>> ((PoolingHttpClientConnectionManager) connManager)
>>>     .setDefaultMaxPerRoute(this.getMaxConnectionPerRoute());
>>> myStrategy = new ConnectionKeepAliveStrategy() {
>>>     public long getKeepAliveDuration(HttpResponse response,
>>>            HttpContext context) {
>>>         // Honor 'keep-alive' header
>>>         HeaderElementIterator it = new BasicHeaderElementIterator(
>>>         response.headerIterator(HTTP.CONN_KEEP_ALIVE));
>>>         while (it.hasNext()) {
>>>             HeaderElement he = it.nextElement();
>>>             String param = he.getName();
>>>             String value = he.getValue();
>>>             if (value != null && param.equalsIgnoreCase("timeout")) {
>>>                 try {
>>>                      return Long.parseLong(value) * 1000;
>>>                 } catch (NumberFormatException ignore) {
>>>             }
>>>          }
>>>       }
>>>       return HttpClientFetcher.this.defaultKeepAlive;
>>>     }
>>>
>>> };
>>> builder.setKeepAliveStrategy(myStrategy);
>>> client = builder.setConnectionManager(connManager)
>>> .setProxy(getProxy())
>>> .setRetryHandler(new MyHttpRequestRetryHander(retryCount))
>>> .setDefaultRequestConfig(defaultRequestConfig)
>>> .setUserAgent(this.getUserAgent()).build();
>>>
>>
>> Assuming that this.getReadTimeout() returns a positive value, the read
>> operation can still block indefinitely if the server keeps on sending
>> packets often enough to prevent the operation from exceeding the socket
>> timeout value.
>>
>> Oleg
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message