diff --git a/gcloud-java-core/src/main/java/com/google/cloud/BaseServiceException.java b/gcloud-java-core/src/main/java/com/google/cloud/BaseServiceException.java index 79afed2a3af8..c22fcfd44a3a 100644 --- a/gcloud-java-core/src/main/java/com/google/cloud/BaseServiceException.java +++ b/gcloud-java-core/src/main/java/com/google/cloud/BaseServiceException.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.Serializable; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.util.Collections; import java.util.Objects; @@ -187,7 +188,10 @@ protected boolean isRetryable(boolean idempotent, Error error) { } protected boolean isRetryable(boolean idempotent, IOException exception) { - return idempotent && exception instanceof SocketTimeoutException; + boolean exceptionIsRetryable = exception instanceof SocketTimeoutException + || exception instanceof SocketException + || "insufficient data written".equals(exception.getMessage()); + return idempotent && exceptionIsRetryable; } /** diff --git a/gcloud-java-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/gcloud-java-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 52bc3b2b51a4..4517afff44ae 100644 --- a/gcloud-java-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/gcloud-java-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -32,6 +32,7 @@ import org.junit.Test; import java.io.IOException; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.util.Set; @@ -101,6 +102,21 @@ public void testBaseServiceException() { serviceException = new BaseServiceException(exception, true); assertTrue(serviceException.retryable()); assertTrue(serviceException.idempotent()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new SocketException(); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.retryable()); + assertTrue(serviceException.idempotent()); + assertNull(serviceException.getMessage()); + assertEquals(exception, serviceException.getCause()); + + exception = new IOException("insufficient data written"); + serviceException = new BaseServiceException(exception, true); + assertTrue(serviceException.retryable()); + assertTrue(serviceException.idempotent()); + assertEquals("insufficient data written", serviceException.getMessage()); assertEquals(exception, serviceException.getCause()); GoogleJsonError error = new GoogleJsonError();