8236413: AbstractConnectTimeout should tolerate both NoRouteToHostException and UnresolvedAddressException
Reviewed-by: aefimov, michaelm
This commit is contained in:
parent
936a7acf32
commit
fab6158c19
@ -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
|
||||
@ -33,6 +33,7 @@ import java.net.http.HttpRequest;
|
||||
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;
|
||||
@ -142,11 +143,11 @@ public abstract class AbstractConnectTimeout {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -194,10 +195,10 @@ public abstract class AbstractConnectTimeout {
|
||||
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);
|
||||
}
|
||||
@ -205,6 +206,12 @@ public abstract class AbstractConnectTimeout {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user