hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: getMethod.getResponseBody() leaks handles
Date Mon, 11 Aug 2003 23:54:26 GMT
Hi David,

Please see my responses below.

> However, I can see no justification for the difference in behavior 
> between
> getResponseBody and getResponseBodyAsStream  -especially as all
> getResponseBody does is call getResponseBodyAsStream.   The difference 
> is
> caused solely by the line 689 mentioned below and it should be removed.

The sole reason for the HttpMethod keeping hold of the connection is so 
that it can read the response.  Once the response has been read the 
connection is no longer of use.  The main difference between 
getResponseBodyAsStream() and getResponseBody() is that the latter 
reads the entire response and buffers it.  Once that is done the 
connection is no longer needed and it is released.

This is not related to line 689.  Please see 
HttpMethodBase.readResponseBody(HttpConnection) and 
HttpMethodBase.responseBodyConsumed() for more details regarding 
connection auto release.

Just to note there is no harm is calling HttpMethod.releaseConnection() 
when the connection has already been released.

> Yes I could change to a single instance of the http client, but I 
> really
> don't see why I have to keep an open connection between get method
> invocations.  If I have finished with the connection and have asked 
> for it
> to be released, then that is what should happen.

Please feel free to override the default behavior so suit your needs.  
By default HttpMethod just releases connections and only forces a close 
when necessary.  This is to support connection keep-alive and help 
performance where possible.  You can force connection close in a number 
of ways if you like:

1) Call HttpMethod.setRequestHeader("Connection", "close") on all 
methods before you execute.
2) Implement your own HttpConnectionManager that closes all connections 
when released.  If you take a look at SimpleHttpConnectionManager you 
will see how trivial this would be if you were so inclined.

I hope this helps.

Mike


Mime
View raw message