On Tue, 2023-08-29 at 18:55 -0400, Brent Putman wrote:
> 
> On 8/29/23 3:48 AM, Oleg Kalnichevski wrote:
> > 
> > This code is not about connection clean-up, this code is about
> > connection re-use. The resource clean-up is ensured by closing out
> > the
> > response.
> 
> 
> Ok, but then why is EntityUtils.consume(entity) being called at all? 

Again. It is called to make sure the entity has been fully consumed and
the underlying connection the entity has been streaming its content
from is fully re-usable. 

> Seems like it's either necessary to explicitly close the HttpEntity 
> content stream at the end of request processing, or it's not 
> necessary.  If it is necessary, we're pointing out that it's not
> always 
> being done.  If it's not necessary, then what is the point of calling
> EntityUtils.consume(entity), most especially in the catch block for
> the 
> checked exception?
> 
> It's the inconsistency that we're asking about.
> 
> Or I can also just turn the question around and ask: When is it 
> necessary to ensure the request's HttpEntity is closed, such as by 
> calling EntityUtils.consume(entity)?
> 
> 

EntityUtils#consume does not close the entity. It makes sure it has
been fully consumed. 

One should always close HttpEntity. Internally HttpClien can optimize
resource management operations and do only what is strictly necessary.

> > One should almost never, never, ever catch Throwable.
> 
> 
> I would in general agree.  But I think an exception (no pun intended)
> would be for example when you need to intercept the failure and
> perform 
> some necessary cleanup before propagating the error back out.

Unless it catches an Error and then causes yet another Error while
trying to recover from the original one. Errors should never be caught.
They are considered non-recoverable for a reason.

Oleg


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

Reply via email to