[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpclient-users
Subject:    Re: Sockets not closing
From:       Shawn Heisey <apache () elyograg ! org>
Date:       2022-07-07 18:40:25
Message-ID: 3935787f-5dc0-3539-e00e-c4e319bb9ff8 () elyograg ! org
[Download RAW message or body]

On 7/7/22 11:58, Gordon Ross wrote:
> I’ve tried doing the bare minimum of:
> 
> InputStream is = response.getEntity().getContent();
> is.close();
> response.close();

I remember having some problems with connections staying open, leading 
the client to run out.  I was advised to make sure the entity is fully 
consumed.  Try this code instead of those three lines:

HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
is.close();
EntityUtils.consumeQuietly(entity);
response.close();

I am not in any way an expert or even very knowledgeable about 
httpclient, but this looks like what I ended up doing on advice from 
this list, which did fix my problem.  I can't find the code where I did 
this, so I can't verify.

https://hc.apache.org/httpcomponents-core-5.1.x/current/httpcore5/apidocs/org/apache/h \
c/core5/http/io/entity/EntityUtils.html#consumeQuietly(org.apache.hc.core5.http.HttpEntity)


Based on the javadoc, that might close the InputStream too, but someone 
who knows more than I do will have to confirm.

Thanks,
Shawn


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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic