You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Diego Rodriguez <dr...@altiria.com> on 2005/03/22 20:29:10 UTC

testing TimeoutController problem

 Hi,

    I'm using http-client 3.0-rc1 with MultiThreadedHttpConnectionManager with MaxTotalConnection and MaxHostConnection set to 1 to reuse the underlying sockets. I'm trying to test how httclient manages sockets with only one socket and persistence connections, to see if I can trust reusing connections after a problem

    To test that I'm using TimeoutController and a servlet that sends a response and then waits longer than TimeoutController timeout.

    The process starts making the first request to the servlet. The servlet sends the response and everything goes fine in the client side (although the servlet is still holding the connection).

    Then I try to make a second request to the same servlet, it sends the request but then remains frozen, not even the response headers are received. After the timeout of TimeoutController expires, the TimeoutController tries to stop the thread sending an interrrupt signal, but even if I wait to see if thread is dead 100 seconds after, the thread is still alive. Then, I call method.abort(), to abort the request and to see if this closes the underlying socket, and it does, but then the thread comes to life and tries also to close the socket and then I get from thread a java.net.SocketException: socket closed.

    Then I try to make a third request, and every goes fine again.

    My questions are:

    1.- executeMethod does not declare that throws a java.net.SocketException. In javadocs it only says it throws IOException, HttpException, is that correct?

this is the log of the exception

java.net.SocketException: socket closed
 at java.net.SocketInputStream.socketRead0(Native Method)
 at java.net.SocketInputStream.read(SocketInputStream.java:129)
 at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
 at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
 at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77)
 at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105)
 at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1110)
 at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1391)
 at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1830)
 at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1593)
 at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1004)
 at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
 at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:168)
 at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393)
 at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
 at com.runi.commons.http.HttpSend$ExecuteThread.run(HttpSend.java:214)

2.- If I call after first request: method.abort() and method.releaseConnection(), I thought it should close the socket and the second request would be ok, but nothing changes. Is there any way to close the socket after a request calling a method? If I include the header "Connection: close", the socket is closed between requests and the three requests completes fine, but I would prefer to do it calling a method.


This is the code that starts the thread that makes the request

 
  ExecuteThread executeThread = new ExecuteThread(method, hostConfiguration);
 
  try {
      TimeoutController.execute(executeThread, 60000);
  } 
  catch(TimeoutController.TimeoutException e) {
 
   int loopCount = 0;
 
   /* executeThread has been sent an interrupt signal by now */
   while(executeThread.isAlive()) {
    try {
     if(++loopCount > 10) {
      log.fatal("ExecuteThread is still alive");
      break;
     }
     Thread.sleep(1000);
    }
    catch(Throwable t) {
     log.fatal("Exception waiting ExecuteThread's end");
     break;
    }
   }
  }

    And this is the thread that makes the request


 //----------------------------------------------------------
 //--------------INNER CLASS------------------------
 //----------------------------------------------------------

 class ExecuteThread extends Thread {
 
  HttpMethod method;
  HostConfiguration hostConfiguration;

  ExecuteThread(HttpMethod method, HostConfiguration hostConfiguration) {
   this.method = method;
   this.hostConfiguration = hostConfiguration;
  }
  
  public void run() {

   int httpStatus;
   try {
    httpStatus = httpClient.executeMethod(hostConfiguration, method);
   } 
   catch(Throwable t) {
    log.info("Exception: ",t);
   }
  }
 }

Thanks for your help
 
Diego 

Re: testing TimeoutController problem

Posted by Diego Rodriguez <dr...@altiria.com>.
Hi Mike,

    thanks for your response...another question

    I want to override connectionManager.releaseConnection() and close 
always the connection, could you give me an example to do it?

    if in my method I call method.releaseConnection()  and not 
connectionManager.releaseConnection(), the connection get closed always if 
it does in connectionManager.releaseConnection()?


    Many thanks again

        Diego

----- Original Message ----- 
From: "Michael Becke" <mb...@gmail.com>
To: "HttpClient User Discussion" <ht...@jakarta.apache.org>
Sent: Thursday, March 24, 2005 6:08 AM
Subject: Re: testing TimeoutController problem


> Hi Diego,
>
>>     My questions are:
>>
>>     1.- executeMethod does not declare that throws a 
>> java.net.SocketException. In javadocs it only says it throws IOException, 
>> HttpException, is that correct?
>
> Yes, SocketException is a subclass of IOException
>
>> 2.- If I call after first request: method.abort() and 
>> method.releaseConnection(), I thought it should close the socket and the 
>> second request would be ok, but nothing changes. Is there any way to 
>> close the socket after a request calling a method? If I include the 
>> header "Connection: close", the socket is closed between requests and the 
>> three requests completes fine, but I would prefer to do it calling a 
>> method.
>
> Calling abort() will only close the connection if it has not already
> been released.  Connections are automatically released by a method
> when the response has been fully read.  The best way to ensure a
> connection is closed is to override the
> connectionManager.releaseConnection() method.  You can then customize
> if/when a connection is closed on release.
>
> Using the timeout controller the way you describe is probably not the
> best way to test the reliability of the
> MultiThreadedHttpConnectionManager.  Having said that you may want to
> try overriding interrupt() inside ExecuteThread and call abort() and
> releaseConnection() before calling super.interrupt().
>
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
>
> 



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


Re: testing TimeoutController problem

Posted by Michael Becke <mb...@gmail.com>.
Hi Diego,

>     My questions are:
> 
>     1.- executeMethod does not declare that throws a java.net.SocketException. In javadocs it only says it throws IOException, HttpException, is that correct?

Yes, SocketException is a subclass of IOException

> 2.- If I call after first request: method.abort() and method.releaseConnection(), I thought it should close the socket and the second request would be ok, but nothing changes. Is there any way to close the socket after a request calling a method? If I include the header "Connection: close", the socket is closed between requests and the three requests completes fine, but I would prefer to do it calling a method.

Calling abort() will only close the connection if it has not already
been released.  Connections are automatically released by a method
when the response has been fully read.  The best way to ensure a
connection is closed is to override the
connectionManager.releaseConnection() method.  You can then customize
if/when a connection is closed on release.

Using the timeout controller the way you describe is probably not the
best way to test the reliability of the
MultiThreadedHttpConnectionManager.  Having said that you may want to
try overriding interrupt() inside ExecuteThread and call abort() and
releaseConnection() before calling super.interrupt().

Mike

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