I wrote a smaller test program to play around with the various HTTP client timeout settings. I also have a servlet that when called, sleeps for the specified time, then returns a simple response. My test program is a single thread that runs in a loop, executing the servlet. After running it for a few hours, I came back to find it had deadlocked - so I thought you may like to know about it.
Name: main
State: BLOCKED on org.eclipse.jetty.client.HttpConnection@53077fc9 owned by: HttpClient-14
Total blocked: 480 Total waited: 478
Stack trace:
org.eclipse.jetty.client.HttpConnection.dump(HttpConnection.java:720)
org.eclipse.jetty.util.component.AggregateLifeCycle.dump(AggregateLifeCycle.java:240)
org.eclipse.jetty.client.HttpDestination.dump(HttpDestination.java:662)
- locked org.eclipse.jetty.client.HttpDestination@1d10c424
org.eclipse.jetty.util.component.AggregateLifeCycle.dump(AggregateLifeCycle.java:240)
org.eclipse.jetty.client.HttpClient.dump(HttpClient.java:169)
org.eclipse.jetty.util.component.AggregateLifeCycle.dump(AggregateLifeCycle.java:192)
org.eclipse.jetty.client.HttpClient.dump(HttpClient.java:159)
JettyHttpClientTestApp.get(JettyHttpClientTestApp.java:72)
JettyHttpClientTestApp.main(JettyHttpClientTestApp.java:103)
Name: HttpClient-14
State: BLOCKED on org.eclipse.jetty.client.HttpDestination@1d10c424 owned by: main
Total blocked: 2 Total waited: 36
Stack trace:
org.eclipse.jetty.client.HttpDestination.returnConnection(HttpDestination.java:423)
org.eclipse.jetty.client.HttpConnection.handle(HttpConnection.java:402)
- locked org.eclipse.jetty.client.HttpConnection@53077fc9
org.eclipse.jetty.client.SocketConnector$1.run(SocketConnector.java:78)
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
java.lang.Thread.run(Thread.java:619)
The code is pretty simple. The client is constructed like so:
this.client = new HttpClient();
this.client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
this.client.setTimeout(10 * Chrono.ONE_SECOND);
// this.client.setIdleTimeout(30 * Chrono.ONE_SECOND);
this.client.setMaxConnectionsPerAddress(4);
Then we simply loop:
while (true) // keep retrying until we get a response ...
{
System.out.println("JettyHttpClientTestApp.get(): dump:\n" + this.client.dump());
final SimpleTestExchange exchange = new SimpleTestExchange(sleep); // prepare the exchange
try
{
this.client.send(exchange); // asynchronously send the request ...
exchange.waitForPushDone(); // ... then immediately block waiting for a response
return exchange.getResponseContent(); // return the push feed XML response
}
catch (PushFeedTimeoutException e) // if we don't get a response in time ...
{
;
}
}
It appears to come about due to the call to dump(). Should I be doing some explicit locking to utilise dump()?
Greg.