Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: Treat IOExceptions as UNAVAILABLE #3757

Merged
merged 2 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.StatusException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -96,7 +97,14 @@ public void run() {
// https://github.com/google/google-auth-library-java/issues/3 is resolved.
//
// Some implementations may return null here.
Map<String, List<String>> metadata = creds.getRequestMetadata(uri);
Map<String, List<String>> metadata;
try {
metadata = creds.getRequestMetadata(uri);
} catch (IOException e) {
// Since it's an I/O failure, let the call be retried with UNAVAILABLE.
applier.fail(Status.UNAVAILABLE.withCause(e));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a message

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. Done.

return;
}
// Re-use the headers if getRequestMetadata() returns the same map. It may return a
// different map based on the provided URI, i.e., for JWT. However, today it does not
// cache JWT and so we won't bother tring to save its return value based on the URI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,25 @@ public void invalidBase64() throws Exception {
}

@Test
public void credentialsThrows() throws Exception {
IOException exception = new IOException("Broken");
public void credentialsThrowsIoException() throws Exception {
Exception exception = new IOException("Broken");
when(credentials.getRequestMetadata(eq(expectedUri))).thenThrow(exception);

GoogleAuthLibraryCallCredentials callCredentials =
new GoogleAuthLibraryCallCredentials(credentials);
callCredentials.applyRequestMetadata(method, attrs, executor, applier);
assertEquals(1, runPendingRunnables());

verify(credentials).getRequestMetadata(eq(expectedUri));
verify(applier).fail(statusCaptor.capture());
Status status = statusCaptor.getValue();
assertEquals(Status.Code.UNAVAILABLE, status.getCode());
assertEquals(exception, status.getCause());
}

@Test
public void credentialsThrowsRuntimeException() throws Exception {
Exception exception = new RuntimeException("Broken");
when(credentials.getRequestMetadata(eq(expectedUri))).thenThrow(exception);

GoogleAuthLibraryCallCredentials callCredentials =
Expand Down