Skip to content

Commit 44810e9

Browse files
committed
Retry on all SocketExceptions
1 parent d1de464 commit 44810e9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.InputStreamReader;
4242
import java.net.HttpURLConnection;
4343
import java.net.Proxy;
44+
import java.net.SocketException;
4445
import java.net.URI;
4546
import java.net.URL;
4647
import java.net.UnknownHostException;
@@ -275,6 +276,10 @@ protected StorageRetryStrategy getRetryStrategy() {
275276
if (ExceptionsHelper.unwrap(prevThrowable, UnknownHostException.class) != null) {
276277
return true;
277278
}
279+
// Also retry on `SocketException`s
280+
if (ExceptionsHelper.unwrap(prevThrowable, SocketException.class) != null) {
281+
return true;
282+
}
278283
return delegate.shouldRetry(prevThrowable, prevResponse);
279284
}
280285
);

modules/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,17 @@ public void testWriteLargeBlob() throws IOException {
449449
return;
450450
}
451451
}
452-
453-
exchange.sendResponseHeaders(HttpStatus.SC_INTERNAL_SERVER_ERROR, -1);
454452
} else {
455453
ExceptionsHelper.maybeDieOnAnotherThread(
456454
new AssertionError("Unexpected request" + exchange.getRequestMethod() + " " + exchange.getRequestURI())
457455
);
458456
}
457+
458+
if (randomBoolean()) {
459+
exchange.sendResponseHeaders(HttpStatus.SC_INTERNAL_SERVER_ERROR, -1);
460+
} else {
461+
logger.warn("Closing connection without response");
462+
}
459463
}));
460464

461465
if (randomBoolean()) {

0 commit comments

Comments
 (0)