Skip to content

Make readOnlyBearerAuth volatile to prevent data races when executing… #4375

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

raulpardo
Copy link

I have created a related issue here: #4374

Description of the issue and possible solution:

There is a data race (according to the Java memory model) in the field readOnlyBearerAuth in class RegistryClient.java. Due to this data race, it is possible that writes on the variable by one thread are not visible to other threads reading the variable in the future. This can happen, for instance, if two threads concurrent execute doPullBearerAuth() and doPushBearerAuth(). Here is an example of a thread reading stale or outdated values of readOnlyBearerAuth:

Consider two threads t1 and t2 and let readOnlyBearerAuth==false. Consider that t1 executes doPullBearerAuth() and concurrently t2 executes doPushBearerAuth(). The following execution can occur:

  1. t1 reads readOnlyBearerAuth as false in this line
  2. t1 sets the corresponding authenticator
  3. t2 reads readOnlyBearerAuth as false (because there is no happens-before relation between the write by t1 and this read and the java memory model does not ensure that the write by t1 is visible to t2)

Solution to the problem in this PR

Declaring readOnlyBearerAuth as volatile. This removes the data race, and it ensures (as per the java memory model) that the reads always read the latest write on readOnlyBearerAuth

Priority

The execution above may not always occur, but, when it does, it will set incorrectly authorization in the class RegistryClient.java.

Fixes #4374 🛠️

Copy link

google-cla bot commented Mar 27, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

… concurrently doPullBearerAuth() and/or doPushBearerAuth()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data race in field readOnlyBearerAuth in class RegistryClient.java
1 participant