-
Notifications
You must be signed in to change notification settings - Fork 178
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
Using a retry with back off for auth refreshing. #504
Conversation
Sounds like awesome! |
} | ||
|
||
|
||
protected HeaderCacheElement refreshCredentialsWithRetry(BackOff backoff) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private HeaderCacheElement refreshCredentialsWithRetry(@nullable BackOff backoff) {
Can you document this?
I have no problem retrying getting credentials on IOException. If this is intended to fix issue: #475, we need to make sure retrying will actually help. |
protected boolean sleepOrTerminate(BackOff backoff) { | ||
long nextBackOffMillis = 0; | ||
try { | ||
nextBackOffMillis = backoff.nextBackOffMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can clean this up a bit:
long nextBackOffMillis = backoff.nextBackOffMillis();
if (nextBackOffMillis == BackOff.STOP) {
return true;
}
try { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nextBackOffMillis() throws the exception. It's needs to be within the try.
@@ -60,7 +48,7 @@ public void sleep(long ms) throws InterruptedException { | |||
@VisibleForTesting | |||
BackOff currentBackoff; | |||
@VisibleForTesting | |||
Sleeper sleeper = THREAD_SLEEPER; | |||
Sleeper sleeper = Sleeper.THREAD_SLEEPER; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this Sleeper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed adding it earlier. sorry about that.
public interface Sleeper { | ||
void sleep(long ms) throws InterruptedException; | ||
|
||
static Sleeper THREAD_SLEEPER = new Sleeper() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
- private constructor
- static Sleeper INSTANCE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we want multiple implementations for test purposes, INSTANCE seems less informative than THREAD_SLEEPER. Maybe DEFAULT_INSTANCE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a nit. It is up to you.
LGTM, some nits |
538923f
to
5ae164f
Compare
The Credential retrieval has occassional issues under load. Dataflow, for example, will start a whole bunch of jobs that need to get credentials at the same time, and we've seen intermittent failures because of that issue; the retry should fix, or at least improve, those types of situations. Adding a unit test for retry logic in the auth interceptor. Updating the Test as per Kevin's comments. Adding more logging around credential refreshes and retries. Using an explicit start time for the tests in RefreshingOAuth2CredentialsInterceptorTest.
Using a retry with back off for auth refreshing.
The Credential retrieval has occassional issues under load. Dataflow, for example, will start a whole bunch of jobs that need to get credentials at the same time, and we've seen intermittent failures because of that issue; the retry should fix, or at least improve, those types of situations.