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/04 16:12:56 UTC

setBodyCheckTimeout causes problems in closing the connection

Hi,
I'm using the latest build from gump and I've found out that setting the 
option setBodyCheckTimeout(500) (which I need because I perform HEAD 
requests to a lot of different servers) results in the connection not 
being properly closed. This happens with the url
https://www.biomedcentral.com/info/about/peerreview
this doesn't happen using commons-httpclient-2.0-rc1.jar build..

Any suggestions?

many thanks in advance

My log:

1238   DEBUG [Thread-1] methods.HeadMethod - Check for non-compliant 
response body. Timeout in 500
ms
1238   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.isResponseAvailable(int)
1241   DEBUG [Thread-1] httpclient.HttpConnection - Input data not available
1241   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.releaseConnection()
1241   DEBUG [Thread-1] httpclient.HttpConnection - Releasing connection 
back to connection manager
.
1262   DEBUG [Thread-1] httpclient.HttpConnection - An error occurred 
while reading from the socket
, is appears to be stale
java.net.SocketException: Socket Closed
         at java.net.PlainSocketImpl.setOption(PlainSocketImpl.java:177)
         at java.net.Socket.setSoTimeout(Socket.java:898)
         at 
com.sun.net.ssl.internal.ssl.SSLSocketImpl.setSoTimeout(DashoA6275)
         at 
org.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.java:465)
         at 
org.apache.commons.httpclient.HttpConnection.isOpen(HttpConnection.java:396)
         at 
org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnectionWithTimeout(Simpl
eHttpConnectionManager.java:144)
         at 
org.apache.commons.httpclient.HttpMethodDirector.establishValidOpenConnection(HttpMethod
Director.java:231)
         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 CheckClient.run(CheckClient.java:190)
1265   DEBUG [Thread-1] httpclient.HttpConnection - Connection is stale, 
closing...
1265   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.close()
1265   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.closeSockedAndStreams()


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


Re: setBodyCheckTimeout causes problems in closing the connection

Posted by "linea@libero.it" <li...@libero.it>.
Hi,
thank you very much for your reply..
actually, when I'm using the 2.0 build I get this log, in which it looks 
like there is a second attempt to wait for the non-complaint response 
body, but no exception is thrown (i'm just pasting the relevant portions 
here):

1213   DEBUG [Thread-1] methods.HeadMethod - enter 
HeadMethod.readResponseBody(HttpState, HttpConnection)
1213   DEBUG [Thread-1] methods.HeadMethod - Check for non-compliant 
response body. Timeout in 500 ms
1214   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.isResponseAvailable(int)
1216   DEBUG [Thread-1] httpclient.HttpConnection - Input data not available
1217   DEBUG [Thread-1] httpclient.HttpMethodBase - Closing the connection.
1217   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.close()
1217   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.closeSockedAndStreams()
1218   INFO  [Thread-1] httpclient.HttpMethodBase - Recoverable 
exception caught when processing request
1222   DEBUG [Thread-1] httpclient.HttpMethodBase - Attempt number 2 to 
process request
1222   DEBUG [Thread-1] httpclient.HttpMethodBase - Opening the connection.
1222   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.open()
1363   DEBUG [Thread-1] httpclient.HttpMethodBase - enter 
HttpMethodBase.writeRequest(HttpState, HttpConnection)
1364   DEBUG [Thread-1] httpclient.HttpMethodBase - enter 
HttpMethodBase.writeRequestLine(HttpState, HttpConnection)
1364   DEBUG [Thread-1] httpclient.HttpMethodBase - enter 
HttpMethodBase.generateRequestLine(HttpConnection, String, String, 
String, String)
1364   DEBUG [Thread-1] httpclient.wire - >> "HEAD 
/info/about/peerreview HTTP/1.1[\r][\n]"
....
1564   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.flushRequestOutputStream()
1564   DEBUG [Thread-1] httpclient.HttpMethodBase - enter 
HttpMethodBase.readResponse(HttpState, HttpConnection)
1564   DEBUG [Thread-1] methods.HeadMethod - enter 
HeadMethod.readResponseBody(HttpState, HttpConnection)
1564   DEBUG [Thread-1] methods.HeadMethod - Check for non-compliant 
response body. Timeout in 500 ms
1564   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.isResponseAvailable(int)
1646   DEBUG [Thread-1] httpclient.HttpConnection - Input data available
1647   WARN  [Thread-1] methods.HeadMethod - Body content returned in 
response to HTTP HEAD
1648   DEBUG [Thread-1] httpclient.HttpMethodBase - enter 
HttpMethodBase.readResponseBody(HttpState, HttpConnection)
1648   DEBUG [Thread-1] httpclient.HttpMethodBase - enter 
HttpMethodBase.readResponseBody(HttpState, HttpConnection)
1648   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.getResponseInputStream()
1649   DEBUG [Thread-1] httpclient.HttpMethodBase - enter 
HttpMethodBase.canResponseHaveBody(int)
1652   DEBUG [Thread-1] httpclient.HttpMethodBase - Should forcefully 
close connection.
1653   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.close()
1653   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.closeSockedAndStreams()
1653   DEBUG [Thread-1] httpclient.HttpConnection - enter 
HttpConnection.releaseConnection()

I confirm that setting setBodyCheckTimeout(-1) eliminates this behaviour 
  when using 2.0 biuld, as well as the exception being thrown when using 
the 2.1 build.

In my version of EasyX509TrustManager I just let isServerTrusted() to 
always return true, but I don't know if this can impact the problem:

public class EasyX509TrustManager implements X509TrustManager
{
     private X509TrustManager standardTrustManager = null;

     /** Log object for this class. */
     private static final Log LOG = 
LogFactory.getLog(EasyX509TrustManager.class);

     /**
      * Constructor for EasyX509TrustManager.
      */
     public EasyX509TrustManager(KeyStore keystore) throws 
NoSuchAlgorithmException, KeyStoreException {
         super();
         TrustManagerFactory factory = 
TrustManagerFactory.getInstance("SunX509");
         factory.init(keystore);
         TrustManager[] trustmanagers = factory.getTrustManagers();
         if (trustmanagers.length == 0) {
             throw new NoSuchAlgorithmException("SunX509 trust manager 
not supported");
         }
         this.standardTrustManager = (X509TrustManager)trustmanagers[0];
     }

     /**
      * @see 
com.sun.net.ssl.X509TrustManager#isClientTrusted(X509Certificate[])
      */
     public boolean isClientTrusted(X509Certificate[] certificates) {
         return this.standardTrustManager.isClientTrusted(certificates);
     }

     /**
      * @see 
com.sun.net.ssl.X509TrustManager#isServerTrusted(X509Certificate[])
      */
     public boolean isServerTrusted(X509Certificate[] certificates) {
         if ((certificates != null) && LOG.isDebugEnabled()) {
             LOG.debug("Server certificate chain:");
             for (int i = 0; i < certificates.length; i++) {
                 LOG.debug("X509Certificate[" + i + "]=" + certificates[i]);
             }
         }
	/*        if ((certificates != null) && (certificates.length == 1)) {
             X509Certificate certificate = certificates[0];
             try {
                 certificate.checkValidity();
             }
             catch (CertificateException e) {
                 LOG.error(e.toString());
                 return false;
             }
             return true;
         } else {
             return this.standardTrustManager.isServerTrusted(certificates);
	    }*/
	return true;
     }

     /**
      * @see com.sun.net.ssl.X509TrustManager#getAcceptedIssuers()
      */
     public X509Certificate[] getAcceptedIssuers() {
         return this.standardTrustManager.getAcceptedIssuers();
     }
}

Many thanks again..


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


Re: setBodyCheckTimeout causes problems in closing the connection

Posted by Michael Becke <be...@u.washington.edu>.
Hello,

I am attempting the scenario you describe and am having similar yet  
different results.  For me, the problem occurs in both 2.0 as well as  
2.1.  Also, I am getting an exception in  
HttpConnection.isResponseAvailable() when the SO_TIMEOUT is reset in  
the finally clause.  Most likely the difference in behavior is due to  
different SSL implementations and how they handle IO once a socket is  
stale/closed.  SSL seems to be quite non-standard across JVMs.

The stack trace you include below is actually not an error.  It is part  
of the standard process of determining if a connection is stale.  The  
stack trace is printed on DEBUG and is meant for just that purpose.   
Having said that, it seems there are a number of other areas where  
SO_TIMEOUT is set(like in HttpConnection.isResponseAvailable()) that  
are potential problems.  It seems that we should catch the  
SocketExceptions in these other cases and do something more robust.

What does everyone else think?

Mike


My test code:

         Protocol.registerProtocol(
             "https",
             new Protocol("https", new EasySSLProtocolSocketFactory(),  
443));

         HttpClient client = new HttpClient();
         HeadMethod head = new  
HeadMethod("https://www.biomedcentral.com/info/about/peerreview");
         head.setBodyCheckTimeout(500);

         client.executeMethod(head);

         head.releaseConnection();

On Thursday, September 4, 2003, at 10:12 AM, linea@libero.it wrote:

> Hi,
> I'm using the latest build from gump and I've found out that setting  
> the option setBodyCheckTimeout(500) (which I need because I perform  
> HEAD requests to a lot of different servers) results in the connection  
> not being properly closed. This happens with the url
> https://www.biomedcentral.com/info/about/peerreview
> this doesn't happen using commons-httpclient-2.0-rc1.jar build..
>
> Any suggestions?
>
> many thanks in advance
>
> My log:
>
> 1238   DEBUG [Thread-1] methods.HeadMethod - Check for non-compliant  
> response body. Timeout in 500
> ms
> 1238   DEBUG [Thread-1] httpclient.HttpConnection - enter  
> HttpConnection.isResponseAvailable(int)
> 1241   DEBUG [Thread-1] httpclient.HttpConnection - Input data not  
> available
> 1241   DEBUG [Thread-1] httpclient.HttpConnection - enter  
> HttpConnection.releaseConnection()
> 1241   DEBUG [Thread-1] httpclient.HttpConnection - Releasing  
> connection back to connection manager
> .
> 1262   DEBUG [Thread-1] httpclient.HttpConnection - An error occurred  
> while reading from the socket
> , is appears to be stale
> java.net.SocketException: Socket Closed
>         at java.net.PlainSocketImpl.setOption(PlainSocketImpl.java:177)
>         at java.net.Socket.setSoTimeout(Socket.java:898)
>         at  
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.setSoTimeout(DashoA6275)
>         at  
> org.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.jav 
> a:465)
>         at  
> org.apache.commons.httpclient.HttpConnection.isOpen(HttpConnection.java 
> :396)
>         at  
> org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnection 
> WithTimeout(Simpl
> eHttpConnectionManager.java:144)
>         at  
> org.apache.commons.httpclient.HttpMethodDirector.establishValidOpenConn 
> ection(HttpMethod
> Director.java:231)
>         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 CheckClient.run(CheckClient.java:190)
> 1265   DEBUG [Thread-1] httpclient.HttpConnection - Connection is  
> stale, closing...
> 1265   DEBUG [Thread-1] httpclient.HttpConnection - enter  
> HttpConnection.close()
> 1265   DEBUG [Thread-1] httpclient.HttpConnection - enter  
> HttpConnection.closeSockedAndStreams()
>
>
> ---------------------------------------------------------------------
> 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