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: RecoverableException -> connection not released from pool?
Date Fri, 18 Apr 2003 12:31:30 GMT
HttpMethod.releaseConnection() should always be called, regardless of 
if an exception occurs or not.  This method is not automatically called 
by HttpClient or by the method since a connection cannot be released 
until it is no longer going to be used.  For example, when performing a 
GET the connection is not just used to post the request but also to 
read the response.  Since the response is to be handled by the user 
code HttpClient cannot determine on it's own when the connection is no 
longer in use.  In reality, connection release is handled automatically 
for some cases, but it is better to be absolutely sure by calling 
releaseConnection() (especially when using 
MultiThreadedHttpConnectionManager).

Mike

On Friday, April 18, 2003, at 03:34 AM, Jani Mattsson wrote:

> No I am actually calling HttpClient.executeMethod(). But I don't see
> any difference, because at least in the 20030416 nightly drop the last
> line of code in HttpClient.executeMethod() is "return 
> method.execute(state,
> connection)"
> without any enclosing try-finally blocks. Therefore as far as I 
> understand
> there's no difference in this respect whether calling the method 
> directly
> or through HttpClient.
>
> But in any case it feels a little strange that I have to do the 
> releasing,
> couldn't the httpclient do that before returning to my calling method?
>
> Jani
>
> -----Original Message-----
> From: Aurelien Pernoud [mailto:apernoud@sopragroup.com]
> Sent: 17. huhtikuuta 2003 11:43
> To: 'Commons HttpClient Project'
> Subject: RE: RecoverableException -> connection not released from pool?
>
>
>
>
> You have to call httpmethodbase.releaseconnection() in the finally() 
> block
> of your try/catch, if not using httpclient but method directly (which I
> think you are), otherwise it doesn't get released. Sample :
>
> GetMethod method = new GetMethod();
> // add whatever you want to this method
> try
> {
>     method.execute(aState, aConnection);
> }
> catch (Exception e)
> {
> 	//Handle exception
> }
> finally
> {
>     method.releaseConnection();
> }
>
> HTH,
> Aurelien
>
> Jani Mattsson a écrit :
>
>> Hello!
>>
>> I'm experiencing problems using HttpClient with
>> MultiThreadedHttpConnectionManager
>> for connections over HTTPS. For one reason or another I get
>> HttpRecoverableExceptions when executing the methods, and I have code
>> to retry a number of times after such an exception. Now it seems that
>> in case a HttpRecoverableException is thrown,
>> HttpMethodBase.execute() never releases the connection back to the
>> connection manager. Thus when I have a quota of four connections per
>> host, after HttpRecoverableException my HttpClient sits in deadlock
>> waiting for someone to release a connection, in vain.
>>
>> Is this a known problem, or am I perhaps doing something wrong in the
>> way I retry / handle the case when the recoverableexceptions are
>> caught?
>>
>> Best regards,
>>
>> Jani Mattsson
>
> ###########################################
>
> This message has been scanned by F-Secure Anti-Virus for Microsoft 
> Exchange.
> For more information, connect to http://www.F-Secure.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


Mime
View raw message