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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Atomically load from accessState to avoid data race. #2732

Merged
merged 1 commit into from Mar 8, 2023

Conversation

spencerschrock
Copy link
Contributor

What kind of change does this PR introduce?

bug fix

What is the current behavior?

There's a data race in the main binary, which can be seen when built with go build -race

==================
WARNING: DATA RACE
Write at 0x00c0001204a8 by goroutine 43:
  sync/atomic.CompareAndSwapInt64()
      /usr/lib/go-1.19/src/runtime/race_amd64.s:316 +0xb
  sync/atomic.CompareAndSwapInt64()
      <autogenerated>:1 +0x24
  github.com/ossf/scorecard/v4/clients/githubrepo/roundtripper.(*githubTransport).RoundTrip()
      ~/go/src/github.com/spencerschrock/scorecard.git/clients/githubrepo/roundtripper/transport.go:44 +0x8e
      
Previous read at 0x00c0001204a8 by goroutine 60:
  github.com/ossf/scorecard/v4/clients/githubrepo/roundtripper/tokens.(*roundRobinAccessor).Next()
      ~/go/src/github.com/spencerschrock/scorecard.git/clients/githubrepo/roundtripper/tokens/round_robin.go:39 +0x1a6

What is the new behavior (if this is a feature change)?**

The load is done atomically to avoid the race.

  • Tests for the changes have been added (for bug fixes/features)

Which issue(s) this PR fixes

Unblocks #2625

Special notes for your reviewer

Does this PR introduce a user-facing change?

For user-facing changes, please add a concise, human-readable release note to
the release-note

(In particular, describe what changes users might need to make in their
application as a result of this pull request.)


Signed-off-by: Spencer Schrock <sschrock@google.com>
@codecov
Copy link

codecov bot commented Mar 8, 2023

Codecov Report

Merging #2732 (1020927) into main (0c090b3) will not change coverage.
The diff coverage is 0.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2732   +/-   ##
=======================================
  Coverage   49.87%   49.87%           
=======================================
  Files         156      156           
  Lines       11572    11572           
=======================================
  Hits         5772     5772           
  Misses       5450     5450           
  Partials      350      350           

@azeemshaikh38 azeemshaikh38 enabled auto-merge (squash) March 8, 2023 20:18
@azeemshaikh38 azeemshaikh38 merged commit 5f13a66 into ossf:main Mar 8, 2023
@spencerschrock spencerschrock deleted the bug/race-condition branch March 8, 2023 20:55
Shofiya2003 pushed a commit to Shofiya2003/scorecard that referenced this pull request Mar 10, 2023
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Shofiya2003 <shofiyabootwala@gmail.com>
Shofiya2003 pushed a commit to Shofiya2003/scorecard that referenced this pull request Mar 10, 2023
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Shofiya2003 <shofiyabootwala@gmail.com>
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.

None yet

2 participants