You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "linea@libero.it" <li...@libero.it> on 2003/09/12 12:43:47 UTC

ConnectionTimeoutException doesn't releaseConnection()

Hi,

I have noticed that when a ConnectionTimeoutException is thrown, HttpConnection 
doesn't seem to release the connection. If a lot of timeouts are encountered, 
this eventually results in a hang when no more connections are available.
Instead, the connection seems to be correctly released to the 
MultiThreadedHttpConnectionManager if a read timeout occurs,ie a 
java.net.SocketTimeoutException is thrown.
Below is the relevant part of my log..
Thanks

10633  DEBUG [MainCheck1] httpclient.HttpMethodDirector - Execute loop try 1
10633  DEBUG [MainCheck1] httpclient.MultiThreadedHttpConnectionManager - enter 
HttpConnectionManager.getConnectionWithTimeout(HostConfiguration, long)
10633  DEBUG [MainCheck1] httpclient.MultiThreadedHttpConnectionManager - 
HttpConnectionManager.getConnection: 
config=HostConfiguration[host=www.museums.reading.ac.uk, protocol=http:80, 
port=80],timeout = 0
10633  DEBUG [MainCheck1] httpclient.MultiThreadedHttpConnectionManager - enter 
HttpConnectionManager.ConnectionPool.getHostPool(HostConfiguration)
10633  DEBUG [MainCheck1] httpclient.MultiThreadedHttpConnectionManager - enter 
HttpConnectionManager.ConnectionPool.getHostPool(HostConfiguration)
10634  DEBUG [MainCheck1] httpclient.MultiThreadedHttpConnectionManager - 
Allocating new connection, 
hostConfig=HostConfiguration[host=www.museums.reading.ac.uk, protocol=http:80, 
port=80]
10634  DEBUG [MainCheck1] httpclient.HttpConnection - 
HttpConnection.setSoTimeout(3000)
10634  DEBUG [MainCheck1] httpclient.HttpConnection - enter HttpConnection.open()
13644  WARN  [MainCheck1] httpclient.HttpConnection - The host 
www.museums.reading.ac.uk:80 (or pro
xy null:-1) did not accept the connection within timeout of 3000 milliseconds

here no call to HttpConnection.releaseConnection() is performed!



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: ConnectionTimeoutException doesn't releaseConnection()

Posted by Michael Becke <be...@u.washington.edu>.
It's very possible that the code in HEAD does not handle this case  
properly.  If you would open a bug in Bugzilla with this info I will  
take care of the problem this weekend.

Thanks,

Mike

On Friday, September 12, 2003, at 07:40 AM, linea@libero.it wrote:

> Hi,
> this is the pattern I use:
>
> Try {
>      method.execute(...);
>      method.getResponseBodyAsString();
>  } catch (Exception e) {
>      ...
>  } finally {
>      method.releaseConnection();
>      LOG.info("RELEASED");	
>  }
>
> The following log shows that no actual release is performed, even if  
> the message "RELEASED" still appears..instead,the same pattern works  
> for SocketTimeoutException.
> Thanks again
>
> 7955   DEBUG [TimeoutCheck1] httpclient.HttpConnection - enter  
> HttpConnection.readLine()
> 10544  DEBUG [MainCheck2] httpclient.HttpConnection - enter  
> HttpConnection.isResponseAvailable(int)
> 10930  WARN  [MainCheck1] httpclient.HttpConnection - The host  
> www.pccomputing.com:80 (or proxy nul
> l:-1) did not accept the connection within timeout of 3000 milliseconds
> 10931  WARN  [MainCheck1] CheckPerformer - Connection Timeout  
> occurred..
> org.apache.commons.httpclient.HttpConnection$ConnectionTimeoutException
>         at  
> org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:6 
> 59)
>         at  
> org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpCo 
> nnectionAdapter.o
> pen(MultiThreadedHttpConnectionManager.java:957)
>         at  
> org.apache.commons.httpclient.HttpMethodDirector.establishValidOpenConn 
> ection(HttpMethod
> Director.java:253)
>         at  
> org.apache.commons.httpclient.HttpMethodDirector.executeMethodForHost(H 
> ttpMethodDirector
> .java:306)
>         at  
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMeth 
> odDirector.java:1
> 43)
>         at  
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java: 
> 378)
>         at  
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java: 
> 268)
>         at CheckPerformer.checkUrl(PersistenceCheck.java:557)
>         at PersistenceCheck$MainCheck.run(PersistenceCheck.java:306)
> 10932  INFO  [MainCheck1] CheckPerformer - RELEASED
>
> Here still no releaseConnection()
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:  
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:  
> commons-httpclient-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: ConnectionTimeoutException doesn't releaseConnection()

Posted by "linea@libero.it" <li...@libero.it>.
Hi,
this is the pattern I use:

Try {
      method.execute(...);
      method.getResponseBodyAsString();
  } catch (Exception e) {
      ...
  } finally {
      method.releaseConnection();
      LOG.info("RELEASED");	
  }

The following log shows that no actual release is performed, even if the message 
"RELEASED" still appears..instead,the same pattern works for SocketTimeoutException.
Thanks again

7955   DEBUG [TimeoutCheck1] httpclient.HttpConnection - enter 
HttpConnection.readLine()
10544  DEBUG [MainCheck2] httpclient.HttpConnection - enter 
HttpConnection.isResponseAvailable(int)
10930  WARN  [MainCheck1] httpclient.HttpConnection - The host 
www.pccomputing.com:80 (or proxy nul
l:-1) did not accept the connection within timeout of 3000 milliseconds
10931  WARN  [MainCheck1] CheckPerformer - Connection Timeout occurred..
org.apache.commons.httpclient.HttpConnection$ConnectionTimeoutException
         at 
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:659)
         at 
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.o
pen(MultiThreadedHttpConnectionManager.java:957)
         at 
org.apache.commons.httpclient.HttpMethodDirector.establishValidOpenConnection(HttpMethod
Director.java:253)
         at 
org.apache.commons.httpclient.HttpMethodDirector.executeMethodForHost(HttpMethodDirector
.java:306)
         at 
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:1
43)
         at 
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:378)
         at 
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:268)
         at CheckPerformer.checkUrl(PersistenceCheck.java:557)
         at PersistenceCheck$MainCheck.run(PersistenceCheck.java:306)
10932  INFO  [MainCheck1] CheckPerformer - RELEASED

Here still no releaseConnection()




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: ConnectionTimeoutException doesn't releaseConnection()

Posted by Adrian Sutton <ad...@intencha.com>.
On 12/09/2003 8:43 PM, "linea@libero.it" <li...@libero.it> wrote:

> Hi,
> 
> I have noticed that when a ConnectionTimeoutException is thrown,
> HttpConnection 
> doesn't seem to release the connection. If a lot of timeouts are encountered,
> this eventually results in a hang when no more connections are available.
> Instead, the connection seems to be correctly released to the
> MultiThreadedHttpConnectionManager if a read timeout occurs,ie a
> java.net.SocketTimeoutException is thrown.

Hi,
It's generally considered a bad idea to depend on anyone but yourself to
release the connection.  Essentially it follows the "you took it, you put it
back" method.  So you should use a pattern like:

Try {
    method.execute(...);
    method.getResponseBodyAsString();
} catch (Exception e) {
    ...
} finally {
    method.releaseConnection();
}

That will guarantee that the method is always released.  A more detailed
example showing the best way to use HttpClient is in the tutorial
http://jakarta.apache.org/commons/httpclient/tutorial.html

Hope that helps,

Adrian Sutton.

----------------------------------------------
Intencha "tomorrow's technology today"
Ph: 38478913 0422236329
Suite 8/29 Oatland Crescent
Holland Park West 4121
Australia QLD
www.intencha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org