Skip to content

Possible race condition in credential refresh #692

@hiranya911

Description

@hiranya911

We are seeing a possible race condition around credential refresh. We use the following code in an integration test suite to fetch OAuth2 tokens:

    GoogleCredentials credentials = ...;
    try {
      if (forceRefresh) {
        credentials.refresh();
      } else {
        credentials.getRequestMetadata();
      }

      AccessToken token = credentials.getAccessToken();
      return token.getTokenValue();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

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 a NullPointerException at token.getTokenValue(). Any thoughts on what might be going on here? What should we do to ensure that getAccessToken() always returns a non-null value?

Note: In the failing tests, forceRefresh has been set to false. So it should execute the credentials.getRequestMetadata() path.

Metadata

Metadata

Assignees

Labels

priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.status: investigatingThe issue is under investigation, which is determined to be non-trivial.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions