[BUG]Java] Fix a race condition in RetryingOAuth.mustache (#10087)

If there were multiple concurrent requests at a time at which the OAuth token had expired, only a single request would be retried. The other requests would fail because of the expired token, but not be retried and so the failures would be propagated to the caller.
This commit is contained in:
Gareth Smith
2021-08-04 03:06:39 +01:00
committed by GitHub
parent 4d0a40e982
commit 98e4eb708f
10 changed files with 141 additions and 12 deletions

View File

@@ -279,6 +279,12 @@
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.11.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.7</java.version>

View File

@@ -155,14 +155,12 @@ public class RetryingOAuth extends OAuth implements Interceptor {
oAuthClient.accessToken(tokenRequestBuilder.buildBodyMessage());
if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) {
setAccessToken(accessTokenResponse.getAccessToken());
return !getAccessToken().equals(requestAccessToken);
}
} catch (OAuthSystemException | OAuthProblemException e) {
throw new IOException(e);
}
}
return false;
return getAccessToken() == null || !getAccessToken().equals(requestAccessToken);
}
public TokenRequestBuilder getTokenRequestBuilder() {