Details
Description
When connect to a unknown host, the HttpClient will block until timeout even by asynchronous way
My testing code as following
@Test
public void testJettyHttpRequest() {
org.eclipse.jetty.client.HttpClient httpClient = new org.eclipse.jetty.client.HttpClient();
httpClient.setConnectorType(org.eclipse.jetty.client.HttpClient.CONNECTOR_SELECT_CHANNEL);
httpClient.setThreadPool(new QueuedThreadPool(250));
try {
httpClient.start();
for (int i = 0; i < 8; ++i) {
MyContentExchange exchange = new MyContentExchange();
exchange.setMethod("POST");
exchange.setAddress(new Address("unknownhostandip.com", 80));
exchange.setURI("");
exchange.setTimeout(10 * 1000);
httpClient.send(exchange);
}
} catch (Exception e) {
e.printStackTrace();
}
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
class MyContentExchange extends ContentExchange {
public MyContentExchange() {
super(true);
}
@Override
protected void onResponseComplete() throws IOException {
Logger.println("has response");
super.onResponseComplete();
}
@Override
protected void onExpire() {
Logger.println("timeout");
super.onExpire();
}
@Override
protected void onException(Throwable x) {
Logger.println("exception");
super.onException(x);
}
}
As my experiment, if the address exists (ex: google.com), it will send 8 http request out almost at the same time. And each response will be notified when has response.
But when the address doesn't exist (ex: unknownhostandip.com), after the first http request send out, it will block until timeout, then the second http request will send, and so on.
As my opinion, since this is asynchronous http client, it should not be blocked when the target address not exist. This will cause my application to wait too long time for waiting all IPs timeout.
My application is a LAN program, it will try to find if there is a web site exist on specific IP.
When the probe begins, it will try from , for example, 192.168.1.1 to 192.168.1.254, to test if there is any HTTP response to check if it's a website.
I think I can get all request timeout after 10 seconds (for example) at the same time.
Since the HttpClient is asynchronous, I don't know if this is a bug or something I missing?!
I found a similar bug as JETTY-990.
Activity
| Field | Original Value | New Value |
|---|---|---|
| Assignee | Greg Wilkins [ gregw ] |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
The problem seems due to SelectConnector.startConnection() method.
When the first time to connect, it is configured as blocking mode.