Skip to content
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

Change locking for Scorecard interface #478

Merged
merged 3 commits into from
Jan 5, 2024

Conversation

raghavkaul
Copy link

This PR makes the following changes:

  1. Initializes scClients once globally
  2. In Scorecard.Get, use Lock()/Unlock() for reading from the scClients map. This prevents two threads from independently reading the value, both deciding that there's no scClient for their repo, and independently (but not concurrently) creating clients. Although they don't concurrently modify the map, thread 2 will overwrite the scClient created by thread 1.
  3. In Scorecard.Close, use Lock()/Unlock() instead of the R-variants. This prevents the case where two threads Close() both reach the if !ok line with ok == true, and then independently (but not concurrently) attempting ScRepoClient.Close and delete.

This should reduce overall repeated work by making the critical sections larger.

* (Not sure if this is needed, githubclient.Close() is thread safe)

Signed-off-by: Raghav Kaul <[email protected]>
@jeffmendoza jeffmendoza merged commit c2c6202 into ossf:main Jan 5, 2024
5 checks passed
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.

2 participants