Skip to content

Commit

Permalink
Add SocketException and 'insufficient data written' to retryable exce…
Browse files Browse the repository at this point in the history
…ptions (#1187)
  • Loading branch information
mziccard authored Aug 23, 2016
1 parent ad5f29b commit f9bbbd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.Test;

import java.io.IOException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.Set;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f9bbbd4

Please sign in to comment.