On 8/30/23 5:00 AM, Oleg Kalnichevski wrote:

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.


So in the case of an unchecked RuntimeException or other Throwable, that means that via the (lack of) handling in CloseableHttpClient, the connection possibly or probably can not be re-used, and that's considered ok?  And there isn't going to be any other resource leak?

Just so we know, how does the connection pooling layer determine re-usability when the returned connection is evaluated?  Is it just looking at the content InputStream and it's just simply: closed=reusable, open=not-reusable?


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


Well ok, point taken. But in reality, as you and I have both already observed, all the HttpEntity#close impls do is merely close their input streams - which is exactly what EntityUtils#consume does.  So practically-speaking they are the same thing (at this time; maybe not for some future HttpEntity impl).



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


So then you would say that a properly written HttpClientResponseHandler should always call HttpEntity#close(), probably in a try-with-resources? And that the EntityUtils#consume call in the CloseableHttpClient is really just there for the case of an improperly written handler that doesn't do that, and solely so that the connection can be reused?


Again, thanks for all your insight.

--Brent

Reply via email to