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 Maxime Arnstamm <ma...@gmail.com> on 2008/02/15 12:45:34 UTC

How to close an idle connection ?

Hi,

I use HttpClient to connect my client application to a server.

While testing, I saw a problem: sometimes, the server accepts the POST but
never answers to it.
So, my HttpClient waits about 1h30 before closing the connection:

[21:26:10] DEBUG (EntityEnclosingMethod.java:504) -> Request body sent
[21:26:10] TRACE (HttpConnection.java:825) -> enter
HttpConnection.flushRequestOutputStream()
[21:26:10] TRACE (HttpMethodBase.java:1585) -> enter
HttpMethodBase.readResponse(HttpState, HttpConnection)
[21:26:10] TRACE (HttpMethodBase.java:1823) -> enter
HttpMethodBase.readStatusLine(HttpState, HttpConnection)
[21:26:10] TRACE (HttpConnection.java:1112) -> enter HttpConnection.readLine
()
[21:26:10] TRACE (HttpParser.java:104) -> enter
HttpParser.readLine(InputStream,
String)
[21:26:10] TRACE (HttpParser.java:73) -> enter HttpParser.readRawLine()

[23:13:28] DEBUG (HttpMethodDirector.java:403) -> Closing the connection.
[23:13:28] TRACE (HttpConnection.java:1147) -> enter HttpConnection.close()
[23:13:28] TRACE (HttpConnection.java:1214) -> enter
HttpConnection.closeSockedAndStreams()
[23:13:28] DEBUG (HttpMethodDirector.java:433) -> Method retry handler
returned false. Automatic recovery will not be attempted
[23:13:28] TRACE (HttpConnection.java:1173) -> enter
HttpConnection.releaseConnection()
[23:13:28] DEBUG (HttpConnection.java:1177) -> Releasing connection back to
connection manager.
[23:13:28] TRACE (HttpConnection.java:1173) -> enter
HttpConnection.releaseConnection()
[23:13:28] DEBUG (HttpConnection.java:1177) -> Releasing connection back to
connection manager.
[23:13:28] TRACE (PostMethod.java:151) -> enter PostMethod.clearRequestBody
()
[23:13:28] TRACE (EntityEnclosingMethod.java:149) -> enter
EntityEnclosingMethod.clearRequestBody()

How can I force the client to close this connection after 5 or 10 minutes ?

I tried to configure the HttpConnectionManager :

HttpConnectionManager hcm = new SimpleHttpConnectionManager();
hcm.closeIdleConnections(5 * 1000 * 60); // five minutes
myclient.setHttpConnectionManager(hcm);

But the problem is still here.

Thanks

ps : if any of this is not english, I'm sorry.

Re: How to close an idle connection ?

Posted by Roland Weber <os...@dubioso.net>.
Hello Maxime,

Maxime Arnstamm wrote:
> Hi,
> 
> I use HttpClient to connect my client application to a server.
> 
> While testing, I saw a problem: sometimes, the server accepts the POST but
> never answers to it.
> So, my HttpClient waits about 1h30 before closing the connection:

Start a "timeout" thread before executing the post method.
The timeout thread should wake up after x minutes and call
method.abort() to cancel the communication.

cheers,
   Roland


> 
> [21:26:10] DEBUG (EntityEnclosingMethod.java:504) -> Request body sent
> [21:26:10] TRACE (HttpConnection.java:825) -> enter
> HttpConnection.flushRequestOutputStream()
> [21:26:10] TRACE (HttpMethodBase.java:1585) -> enter
> HttpMethodBase.readResponse(HttpState, HttpConnection)
> [21:26:10] TRACE (HttpMethodBase.java:1823) -> enter
> HttpMethodBase.readStatusLine(HttpState, HttpConnection)
> [21:26:10] TRACE (HttpConnection.java:1112) -> enter HttpConnection.readLine
> ()
> [21:26:10] TRACE (HttpParser.java:104) -> enter
> HttpParser.readLine(InputStream,
> String)
> [21:26:10] TRACE (HttpParser.java:73) -> enter HttpParser.readRawLine()
> 
> [23:13:28] DEBUG (HttpMethodDirector.java:403) -> Closing the connection.
> [23:13:28] TRACE (HttpConnection.java:1147) -> enter HttpConnection.close()
> [23:13:28] TRACE (HttpConnection.java:1214) -> enter
> HttpConnection.closeSockedAndStreams()
> [23:13:28] DEBUG (HttpMethodDirector.java:433) -> Method retry handler
> returned false. Automatic recovery will not be attempted
> [23:13:28] TRACE (HttpConnection.java:1173) -> enter
> HttpConnection.releaseConnection()
> [23:13:28] DEBUG (HttpConnection.java:1177) -> Releasing connection back to
> connection manager.
> [23:13:28] TRACE (HttpConnection.java:1173) -> enter
> HttpConnection.releaseConnection()
> [23:13:28] DEBUG (HttpConnection.java:1177) -> Releasing connection back to
> connection manager.
> [23:13:28] TRACE (PostMethod.java:151) -> enter PostMethod.clearRequestBody
> ()
> [23:13:28] TRACE (EntityEnclosingMethod.java:149) -> enter
> EntityEnclosingMethod.clearRequestBody()
> 
> How can I force the client to close this connection after 5 or 10 minutes ?
> 
> I tried to configure the HttpConnectionManager :
> 
> HttpConnectionManager hcm = new SimpleHttpConnectionManager();
> hcm.closeIdleConnections(5 * 1000 * 60); // five minutes
> myclient.setHttpConnectionManager(hcm);
> 
> But the problem is still here.
> 
> Thanks
> 
> ps : if any of this is not english, I'm sorry.
> 


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