Unexplained TimeOut

72 views
Skip to first unread message

avi maslati

unread,
Dec 16, 2019, 5:02:21 AM12/16/19
to asyncht...@googlegroups.com
Hi Guys,

Running the following code almost ended with time out (I made sure the server always responds)
and nothing is printed to screen.
Changing the first  thenApply to  thenApplyAsync solves the problem.

I am not sure if this code is supported, and I'd appreciate it if someone can shed some light on this.
I am using AHC 2.10.0 on windows 7.
public static void main(String[] args) throws Exception {
AsyncHttpClient client = Dsl.asyncHttpClient();

client.prepareGet("http://google.com").execute()
.toCompletableFuture()
.thenApply(response -> client.prepareGet("http://google.com")
.execute()
.toCompletableFuture().join()
.getResponseBody())
.thenAccept(s -> System.out.println(s))
.exceptionally(t->{System.out.println(t.getMessage()); return null;});
Thread.sleep(1000000);
client.close();
}

Thanks
Avi

Stéphane LANDELLE

unread,
Dec 16, 2019, 5:58:12 AM12/16/19
to asyncht...@googlegroups.com
YOU MUST NOT BLOCK IN I/O THREADS!!!

try(AsyncHttpClient client = asyncHttpClient()) {
  client.prepareGet("https://google.com").execute()
    .toCompletableFuture()
    .thenCompose(response -> client.prepareGet("https://google.com")
      .execute()
      .toCompletableFuture()
      .thenApply(Response::getResponseBody))
    .thenAccept(System.out::println)

    .exceptionally(t->{System.out.println(t.getMessage()); return null;});
  Thread.sleep(1000000);
}


Logo Stéphane Landelle
Chief Technical Officer
twitter: @slandelle
site:
gatling.io




--
You received this message because you are subscribed to the Google Groups "asynchttpclient" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asynchttpclie...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/asynchttpclient/CANxoBk30Ru007atuhbMCtgScUZt0mkZgoLEMyQ6d7Fhug_MsJg%40mail.gmail.com.

Matt Farmer

unread,
Dec 27, 2019, 10:03:17 AM12/27/19
to asyncht...@googlegroups.com
For posterity, can you try upgrading to 2.10.4 to see if the behavior changes?

--

avi maslati

unread,
Dec 27, 2019, 3:56:56 PM12/27/19
to asyncht...@googlegroups.com
The behavior is exactly the same in version 2.10.4, probably it's because of blocking the I/O thread as  Stéphane Landelle wrote below.

Reply all
Reply to author
Forward
0 new messages