Sorry might have jumped the gun, is the issue here likely a lack of setSoTimeout (not shown)?
When I saw setConnectionTimeout was set, I wrongly thought my bases were covered. Especially because things were working for so long and suddenly breaking every few hours. On Wed, Aug 27, 2014 at 1:21 PM, Jon Wu <[email protected]> wrote: > Hi, > > I can't figure out why my code to fetch an HTTP resource hangs in > EntityUtils.toString(). > > I'm running Java 6 with HttpClient 4.3.5. I had been using code like > this to reload a Guava cache. It was working for about a year twice / > minute, but recently, my cache stopped reloading reliably and > EntityUtils.toString() started to hang after ~10-1000 requests. I > tried updating from 4.1.2 (which had been working) to 4.3.5, but that > didn't help. > > My code looks like this: > > HttpEntity entity = null; > try { > entity = PooledHttpClient.getHttpEntity(new HttpGet(location)); > // PROBLEM HERE: Deadlock occurs rarely in EntityUtils.toString() > final String resource = EntityUtils.toString(entity); > return resource; > } catch (Exception e) { > // Something went wrong, log the error or retry > } finally { > EntityUtils.consume(entity); > } > > Here's where it's getting stuck: > > java.lang.Thread.State: RUNNABLE > at java.net.SocketInputStream.socketRead0(Native Method) > at java.net.SocketInputStream.read(SocketInputStream.java:129) > at > org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:198) > at > org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178) > at > org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137) > at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) > at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) > at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) > - locked <0x000000008a259028> (a java.io.InputStreamReader) > at java.io.InputStreamReader.read(InputStreamReader.java:167) > at java.io.Reader.read(Reader.java:123) > at org.apache.http.util.EntityUtils.toString(EntityUtils.java:244) > at org.apache.http.util.EntityUtils.toString(EntityUtils.java:288) > at com.x.template.Resource.getResource(Resource.java:217) > > I still haven't run into an issue on my dev machine on OS X, but > production is running on Joyent's SmartOS (Intel Solaris). > > I'm pretty stumped, any help would be GREATLY APPRECIATED! > > Thanks, > Jon --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
