The main different cause this problem occur is in the
org.eclipse.jetty.client.SelectConnector.startConnection() method.

 

In this method, it will tune the SocketChannel as blocking or non-blocking.

 

In Jetty 7.1.6, it coded "channel.configureBlocking( false );", so test code
passed.

 

In Jetty 7.3.0, it coded "channel.configureBlocking( true );", although it
turn the channel to non-blocking after channel.connect(), but the point is
when channel try to connect to a doesn't exist ip, it will blocking until
timeout. And this is what I didn't expect.

 

Reference:

Jetty 7.1.6:
http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/tags/jetty-7.1.6.v
20100715/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector
.java

Jetty 7.3.0:
http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/tags/jetty-7.3.0.v
20110203/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector
.java

 

 

Sincerely,

Micky

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Micky Lee
Sent: Thursday, February 17, 2011 12:07 PM
To: [email protected]
Cc: 'Victor Liu'
Subject: [jetty-users] Async of HttpClient does not work on Jetty 7.2.2 and
7.3.0?

 

Hi all,

 

I need to send async http request to an URL at the same time and I use Jetty
HttpClient to test.

 

According to the result log, the Jetty 7.1.6 is able to do correct async but
the Jetty 7.2.2/7.3.0 does not.

 

Logs about Jetty 7.1.6: http://tinypaste.com/a7a226

Logs about Jetty 7.3.0: http://tinypaste.com/11a349

 

Here is the test code

 

 

@Test

    public void asyncConnectInvalidFuture() throws Throwable {

        

        HttpClient httpClient = new HttpClient();

        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);

    

         httpClient.setConnectTimeout(10 * 1000);

        try {

            httpClient.start();

            

            for (int i = 0; i < 4; ++i) {

                HttpExchange exchange = new HttpExchange();

                exchange.setMethod("GET");

                exchange.setURL("http://192.168.99.99";);

                exchange.setRequestHeader(HttpHeaders.CONNECTION,
HttpHeaderValues.KEEP_ALIVE);

                httpClient.send(exchange);  

            }

        } catch (Exception e) {

            e.printStackTrace();

        }

        

        synchronized (this) {

            try {

                wait();

            } catch (InterruptedException e) {

                e.printStackTrace();

            }

        }

    }

 

Should notice that the IP 192.168.99.99 does not exist, so it must get
timeout exception.

In the correct async scenario, the 4 requests should be sent at the same
time and they timeout almost at the same time as Jetty 7.1.6 logs described.

But the Jetty 7.3.0 does not use the scenario, according to the logs, it
sends first request and waits for timeout, then sends the second request and
so on. So we see the logs just 10 seconds after another request by each.

 

I doubt HttpClient asynchronous function when this scenario.

 

Why 7.1.6 is OK and 7.2.2/7.3.0 NOK?

Is this a bug? 

 

 

Sincerely,

Micky

 

 

_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to