3

After some usage, HttpClient seems to block here, causing my whole app to freeze:

Thread [main] (Suspended)   
    Unsafe.park(boolean, long) line: not available [native method]  
    LockSupport.park(Object) line: 186  
    AbstractQueuedSynchronizer$ConditionObject.await() line: 2043   
    AbstractConnPool$2(PoolEntryFuture<T>).await(Date) line: 131    
    HttpConnPool(AbstractConnPool<T,C,E>).getPoolEntryBlocking(T, Object, long, TimeUnit, PoolEntryFuture<E>) line: 281 
    AbstractConnPool<T,C,E>.access$000(AbstractConnPool, Object, Object, long, TimeUnit, PoolEntryFuture) line: 62  
    AbstractConnPool$2.getPoolEntry(long, TimeUnit) line: 176   
    AbstractConnPool$2.getPoolEntry(long, TimeUnit) line: 172   
    AbstractConnPool$2(PoolEntryFuture<T>).get(long, TimeUnit) line: 100    
    PoolingClientConnectionManager.leaseConnection(Future<HttpPoolEntry>, long, TimeUnit) line: 212 
    PoolingClientConnectionManager$1.getConnection(long, TimeUnit) line: 199    
    DefaultRequestDirector.execute(HttpHost, HttpRequest, HttpContext) line: 453    
    ContentEncodingHttpClient(AbstractHttpClient).execute(HttpHost, HttpRequest, HttpContext) line: 927 
    ContentEncodingHttpClient(AbstractHttpClient).execute(HttpUriRequest, HttpContext) line: 826    
    ContentEncodingHttpClient(AbstractHttpClient).execute(HttpUriRequest) line: 804 
    ...

I don't see any "close()" or "release()" method on the returned HttpResponse, what am I not doing here that I need to be doing?

Per request, here is my code:

final HttpResponse hr = Misc.httpClient.execute(hg);
if (hr.getEntity().getContentType().getValue().toLowerCase().contains("html")) {
    final Document doc = Jsoup.parse(hr.getEntity().getContent(), ContentType.getOrDefault(hr.getEntity()).getCharset(), urlAsString);
    processDocument(url, doc);
} else if (hr.getEntity().getContentType().getValue().toLowerCase().contains("text/xml")) {
    final SyndFeedInput input = new SyndFeedInput();

    rssFeed = input.build(new InputStreamReader(hr.getEntity().getContent()));
}
1
  • Show us your code, how you use the HttpClient API. For starters try using execute() with ResponseHandler parameter Commented Jul 9, 2012 at 16:37

2 Answers 2

8

The InputStream that you get from your HttpResponse needs to have close() called on it. There's no close() for HttpResponse itself.

For example, when you get your HttpResponse and call getEntity() to get an HttpEntity, calling getContent() to get the InputStream, after you've done reading the content, call close() on the InputStream.

Sign up to request clarification or add additional context in comments.

Comments

0

More details would help but here are few reasons that things like this might happen:

  1. You keep opening connections to the same server and expect the server to close them while the server expects you to reuse the connection (http1.1) so you actually have a leak.

  2. You may have connectivity problem in the underlying transport (routing etc) that causes this, so the httpclient is waiting for TCP to timeout.

  3. The server is keeping the connection open because it's busy but hasn't replied yet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.