Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8164527

HTTP_1_1 client doesn't care timeout on async mode

XMLWordPrintable

      import java.net.URI;
      import java.net.http.HttpClient;
      import java.net.http.HttpResponse;
      import java.time.Duration;
      import java.util.concurrent.CompletableFuture;

      public class SimpleTimeoutTest {

          public static void main(String[] args) throws Exception {
              String uri = "..."; // a long time access
              HttpClient client = HttpClient.create().build();
              CompletableFuture<HttpResponse<String>> responseFC = client
                      .request(new URI(uri)).timeout(Duration.ofSeconds(1)).GET()
                      .responseAsync(HttpResponse.BodyHandler.asString());
              System.out.println(responseFC.join().body());
          }
      }

      The above test doesn't throw HttpTimeoutException and cannot finish.

            dfuchs Daniel Fuchs
            jjiang John Jiang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: