Skip to content

Commit 19e964a

Browse files
authored
Expand OkHttp default retry exception predicate with SocketException (#7057)
1 parent bf71be1 commit 19e964a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/RetryInterceptor.java

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.opentelemetry.sdk.common.export.RetryPolicy;
1111
import java.io.IOException;
1212
import java.net.ConnectException;
13+
import java.net.SocketException;
1314
import java.net.SocketTimeoutException;
1415
import java.net.UnknownHostException;
1516
import java.util.StringJoiner;
@@ -158,12 +159,15 @@ static boolean isRetryableException(IOException e) {
158159
// Known retryable ConnectTimeout messages: "Failed to connect to
159160
// localhost/[0:0:0:0:0:0:0:1]:62611"
160161
// Known retryable UnknownHostException messages: "xxxxxx.com"
162+
// Known retryable SocketException: Socket closed
161163
if (e instanceof SocketTimeoutException) {
162164
return true;
163165
} else if (e instanceof ConnectException) {
164166
return true;
165167
} else if (e instanceof UnknownHostException) {
166168
return true;
169+
} else if (e instanceof SocketException) {
170+
return true;
167171
}
168172
return false;
169173
}

exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/RetryInterceptorTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.net.ConnectException;
2727
import java.net.HttpRetryException;
2828
import java.net.ServerSocket;
29+
import java.net.SocketException;
2930
import java.net.SocketTimeoutException;
3031
import java.net.UnknownHostException;
3132
import java.time.Duration;
@@ -237,6 +238,8 @@ private static Stream<Arguments> isRetryableExceptionArgs() {
237238
Arguments.of(new SocketTimeoutException(), true),
238239
// Should retry on UnknownHostExceptions
239240
Arguments.of(new UnknownHostException("host"), true),
241+
// Should retry on SocketException
242+
Arguments.of(new SocketException("closed"), true),
240243
// Should retry on ConnectException
241244
Arguments.of(
242245
new ConnectException("Failed to connect to localhost/[0:0:0:0:0:0:0:1]:62611"), true),

0 commit comments

Comments
 (0)