Expand OkHttp default retry exception predicate with SocketException (#7057)

This commit is contained in:
Yuriy Holinko 2025-01-31 04:51:01 +07:00 committed by GitHub
parent bf71be17d4
commit 19e964a636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import static java.util.stream.Collectors.joining;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.StringJoiner;
@ -158,12 +159,15 @@ public final class RetryInterceptor implements Interceptor {
// Known retryable ConnectTimeout messages: "Failed to connect to
// localhost/[0:0:0:0:0:0:0:1]:62611"
// Known retryable UnknownHostException messages: "xxxxxx.com"
// Known retryable SocketException: Socket closed
if (e instanceof SocketTimeoutException) {
return true;
} else if (e instanceof ConnectException) {
return true;
} else if (e instanceof UnknownHostException) {
return true;
} else if (e instanceof SocketException) {
return true;
}
return false;
}

View File

@ -26,6 +26,7 @@ import java.io.IOException;
import java.net.ConnectException;
import java.net.HttpRetryException;
import java.net.ServerSocket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.time.Duration;
@ -237,6 +238,8 @@ class RetryInterceptorTest {
Arguments.of(new SocketTimeoutException(), true),
// Should retry on UnknownHostExceptions
Arguments.of(new UnknownHostException("host"), true),
// Should retry on SocketException
Arguments.of(new SocketException("closed"), true),
// Should retry on ConnectException
Arguments.of(
new ConnectException("Failed to connect to localhost/[0:0:0:0:0:0:0:1]:62611"), true),