-
Notifications
You must be signed in to change notification settings - Fork 216
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
Possible race condition in credential refresh #692
Comments
Seeing more strange behavior. Was trying to debug the above issue a bit further by running the following simple test case: GoogleCredentials cred = loadServiceAccount();
cred.refresh();
String t1 = cred.getAccessToken().getTokenValue();
// Thread.sleep(1000);
cred.refresh();
String t2 = cred.getAccessToken().getTokenValue();
assertNotEquals(t1, t2); But this would fail most of the time:
Introducing some delay before the second refresh operation (just uncomment the sleep), increases success rate greatly. |
This happens randomly for us about once or twice per week. It occurs both locally on developer machines as well as in deployed environments such as staging and production.
From this we see exceptions with these sample stack traces:
The effect of this for us is that our applications randomly fail to start. Please fix this. |
This reverts commit 514ffe3.
🤖 I have created a release *beep* *boop* --- ## [1.12.1](https://togithub.com/googleapis/google-auth-library-java/compare/v1.12.0...v1.12.1) (2022-10-18) ### Bug Fixes * Resolve race condition reported in [#692](https://togithub.com/googleapis/google-auth-library-java/issues/692) ([#1031](https://togithub.com/googleapis/google-auth-library-java/issues/1031)) ([87a6606](https://togithub.com/googleapis/google-auth-library-java/commit/87a66067dff49d68f5b01cfe4c3f755fbf6b44fb)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
We are seeing a possible race condition around credential refresh. We use the following code in an integration test suite to fetch OAuth2 tokens:
We expect the
credentials
to contain a valid access token at the end of the if-else block. However, our tests intermittently fail by throwing aNullPointerException
attoken.getTokenValue()
. Any thoughts on what might be going on here? What should we do to ensure thatgetAccessToken()
always returns a non-null value?Note: In the failing tests,
forceRefresh
has been set tofalse
. So it should execute thecredentials.getRequestMetadata()
path.The text was updated successfully, but these errors were encountered: