hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Diego Rodriguez" <drodrig...@altiria.com>
Subject testing TimeoutController problem
Date Tue, 22 Mar 2005 19:29:10 GMT


    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");
    catch(Throwable t) {
     log.fatal("Exception waiting ExecuteThread's end");

    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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message