You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Matthew McGowan <ma...@nynodata.no> on 2003/11/18 12:44:54 UTC
read timeout with persistent connection
Greetings,
With HttpClient, I'm using the MultiThreadedHttpConnectionManager, with
all timeout values set to 30s, and I'm seeing a problem against a server
that discards unused connections after several minutes. It seems the
connection close isn't detected by the HttpConnection.isStale() method,
which causes a delay in processing as stream reading blocks waiting for
the socket timeout.
In HttpConnection.isStale, the stream read throws a
SocketTimeoutException which indicates the socket is still alive, so the
connection is reused in HttpMethodBase.processRequest without closing
the socket first.
The request is successfully written via writeRequest, but readResponse
throws a java.net.SocketTimeoutException, after delaying for 30s.
private void processRequest(HttpState state, HttpConnection
connection)
throws HttpException, IOException {
LOG.trace("enter HttpMethodBase.processRequest(HttpState,
HttpConnection)");
...
if (!connection.isOpen()) {
// returns true
LOG.debug("Opening the connection.");
connection.open();
}
writeRequest(state, connection);
requestSent = true;
readResponse(state, connection);
// the response read times out
// the method has successfully executed
used = true;
break;
There is a pattern - this happens only after connections have not been
used for a certain period of time, where I presume the origin server is
closing the unused persistent connection. If connections are reused
frequently, then there are no problems - the timeout occurs only when
connections lay idle for a few minutes.
The externally visible behavior to users is that the request takes at
least 30s to execute - the request is retried, so it eventually
succeeds.
Any ideas how I go about fixing this? I'm not entirely sure if this is a
problem with HTTPClient or with the origin server (which is running MS
IIS 4.0, not under my control.)
I've included below a simple test case to demonstrate the problem.
Thanks for any help!
mat mcgowan
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.*;
import java.io.IOException;
import junit.framework.TestCase;
public class TestJakartaHttpClient extends TestCase
{
public void testNorgeNo() throws InterruptedException,
IOException
{
httpServer("http://norge.no", 5*1000*60);
}
public void httpServer(String uri, int delay) throws
IOException, InterruptedException
{
HttpClient client = new HttpClient(new
MultiThreadedHttpConnectionManager());
int timeout = 30*1000;
client.setConnectionTimeout(timeout);
client.setHttpConnectionFactoryTimeout(timeout) ;
client.setTimeout(timeout);
GetMethod m = new GetMethod(uri);
m.setStrictMode(false);
m.setFollowRedirects(false);
m.setDoAuthentication(false);
m.setHttp11(true);
// read data
client.executeMethod(m);
m.getResponseBody();
Thread.sleep(delay);
try
{
m = new GetMethod(uri);
m.setStrictMode(false);
m.setFollowRedirects(false);
m.setDoAuthentication(false);
m.setHttp11(true);
client.executeMethod(m);
m.getResponseBody();
}
catch (HttpRecoverableException ex)
{
fail(ex.toString());
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: read timeout with persistent connection
Posted by Ortwin Glück <or...@nose.ch>.
There is an option to disable stale checking.
Matthew McGowan wrote:
> Any ideas how I go about fixing this?
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org