Hi,
I have a problem with HttpClient 3.0.1.
I work on a commercial project which has a lot of machines deployed in the
field which periodically call back to our data centre. The backend is
Tomcat, and the client machines run a Java process, scheduled by cron, a few
times every day.
Originally, the client was implemented using java.net.URLConnection. I found
that URLConnection occasionally appeared to hang, and there did not appear
to be a way to configure soTimeout with URLConnections. So I replaced all
our code that used java.net.URLConnection with HTTPClient.
For several months, this appeared to have worked, but recently we have been
experiencing similar issues again. By this I mean that the soTimeout period
is exceeded, and the client appears to be blocked on
java.net.SocketInputStream.socketRead0 forever. This occurs seemingly at
random, and I cannot reproduce it on demand.
To help elucidate this problem, I wrote a small test servlet which sleeps
for the requested number of seconds to simulate timeouts. When using this
test servlet, I get java.net.SocketTimeoutException as expected.
Please see below the code I am using to set the timeout and the result of
kill -QUIT on the Java client process. On the client, uname -a displays:
Linux myhost 2.6.9-34.0.2.ELsmp #1 SMP Fri Jul 7 19:52:49 CDT 2006 i686 i686
i386 GNU/Linux
As shown in the thread dump, we are using Java 1.4.2_01-b06. My feeling is
this is probably a bug in Java's native networking library, but I can't be
sure about that because the problem is not reproducible on demand. I also
cannot easily upgrade the JVM on the client machines as they are all
deployed at our customer sites. Also, I cannot find anything relevant in
Sun's Java bug database.
Any help would be greatly appreciated.
============= setup code (slightly sanitised) ======================
private static HttpClient getHttpClient(final Properties props)
{
// Set socks properties in case we are using SOCKS
System.setProperty("java.net.socks.username", "username");
System.setProperty("java.net.socks.password", "password");
int httpConnectTimeoutSecs = 60;
int httpTimeoutMins = 60;
SimpleHttpConnectionManager cm = new SimpleHttpConnectionManager();
HttpConnectionManagerParams params = cm.getParams();
params.setConnectionTimeout(httpConnectTimeoutSecs * 1000);
params.setSoTimeout(httpTimeoutMins * 60 * 1000);
cm.setParams(params);
HttpClient client = new HttpClient(cm);
HttpClientParams cparms = client.getParams();
cparms.setAuthenticationPreemptive(true);
HttpState state = client.getState();
state.setCredentials(AuthScope.ANY, new
UsernamePasswordCredentials("username", "password"));
if (proxyUser != null)
{
state.setProxyCredentials(AuthScope.ANY, new
UsernamePasswordCredentials(proxyUser, proxyPwd));
}
return client;
}
=============== thread dump =================================
Full thread dump Java HotSpot(TM) Client VM (1.4.2_01-b06 mixed mode):
"Signal Dispatcher" daemon prio=1 tid=0x0808def0 nid=0x7f23 waiting on
condition [0..0]
"Finalizer" daemon prio=1 tid=0x0808a560 nid=0x7f23 in Object.wait()
[6f552000..6f55222c]
at java.lang.Object.wait(Native Method)
- waiting on <0x7493bb88> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
- locked <0x7493bb88> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
"Reference Handler" daemon prio=1 tid=0x080889c0 nid=0x7f23 in Object.wait()
[6f5d3000..6f5d322c]
at java.lang.Object.wait(Native Method)
- waiting on <0x7493bbf0> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:429)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
- locked <0x7493bbf0> (a java.lang.ref.Reference$Lock)
"main" prio=1 tid=0x08052df8 nid=0x7f23 runnable [bfffd000..bfffd948]
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)
- locked <0x6fb4bd10> (a java.io.BufferedInputStream)
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:1115)
at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832)
at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at com.somecompany.HttpClientHelper.executeHttpMethod(Unknown
Source)
"VM Thread" prio=1 tid=0x08087608 nid=0x7f23 runnable
"VM Periodic Task Thread" prio=1 tid=0x08090848 nid=0x7f23 waiting on
condition
"Suspend Checker Thread" prio=1 tid=0x0808d498 nid=0x7f23 runnable
_________________________________________________________________
Be the first to hear what's new at MSN - sign up to our free newsletters!
http://www.msn.co.uk/newsletters
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]