Skip to content

Commit

Permalink
8236413: AbstractConnectTimeout should tolerate both NoRouteToHostExc…
Browse files Browse the repository at this point in the history
…eption and UnresolvedAddressException

Reviewed-by: aefimov, michaelm
  • Loading branch information
dfuch committed Dec 8, 2020
1 parent 936a7ac commit fab6158
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/jdk/java/net/httpclient/AbstractConnectTimeout.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,6 +33,7 @@
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.channels.UnresolvedAddressException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -142,11 +143,11 @@ private void timeoutSync(Version requestVersion,
long elapsedTime = NANOSECONDS.toMillis(System.nanoTime() - startTime);
out.printf("Client: received in %d millis%n", elapsedTime);
Throwable t = e.getCause().getCause(); // blocking thread-specific exception
if (!(t instanceof NoRouteToHostException)) { // tolerate only NRTHE
if (!isAcceptableCause(t)) { // tolerate only NRTHE or UAE
e.printStackTrace(out);
fail("Unexpected exception:" + e);
} else {
out.printf("Caught ConnectException with NoRouteToHostException"
out.printf("Caught ConnectException with "
+ " cause: %s - skipping%n", t.getCause());
}
}
Expand Down Expand Up @@ -194,17 +195,23 @@ private void timeoutAsync(Version requestVersion,
long elapsedTime = NANOSECONDS.toMillis(System.nanoTime() - startTime);
out.printf("Client: received in %d millis%n", elapsedTime);
Throwable t = e.getCause();
if (t instanceof ConnectException &&
t.getCause() instanceof NoRouteToHostException) { // tolerate only NRTHE
out.printf("Caught ConnectException with NoRouteToHostException"
+ " cause: %s - skipping%n", t.getCause());
if (t instanceof ConnectException && isAcceptableCause(t.getCause())) {
// tolerate only NRTHE and UAE
out.printf("Caught ConnectException with "
+ "cause: %s - skipping%n", t.getCause());
} else {
assertExceptionTypeAndCause(t);
}
}
}
}

static boolean isAcceptableCause(Throwable cause) {
if (cause instanceof NoRouteToHostException) return true;
if (cause instanceof UnresolvedAddressException) return true;
return false;
}

static HttpClient newClient(Duration connectTimeout, ProxySelector proxy) {
HttpClient.Builder builder = HttpClient.newBuilder().proxy(proxy);
if (connectTimeout != NO_DURATION)
Expand Down

1 comment on commit fab6158

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.