Skip to content

fix: Synchronize requestCount in rate limit tests#4124

Merged
gmlewis merged 1 commit intogoogle:masterfrom
mangomaker5:fix/issue-4055-data-race
Mar 27, 2026
Merged

fix: Synchronize requestCount in rate limit tests#4124
gmlewis merged 1 commit intogoogle:masterfrom
mangomaker5:fix/issue-4055-data-race

Conversation

@mangomaker5
Copy link
Copy Markdown
Contributor

Fixes #4055

The requestCount variable in several rate limit tests was accessed concurrently
by the test goroutine and the background HTTP handler goroutine without
synchronization, causing data races detected on Windows CI.

Changed requestCount from int to atomic.Int32 using sync/atomic.

Verified locally on Windows 11 with Go race detector:

go test -v -race -run "TestDo_rateLimit_abortSleepContextCancelled" -count=5
--- PASS: TestDo_rateLimit_abortSleepContextCancelled (0.01s)
--- PASS: TestDo_rateLimit_abortSleepContextCancelledClientLimit (0.01s)
PASS (all 5 iterations)

go test -v -race -count=1 ./...
ok github.com/google/go-github/v84/github 4.625s

gofmt -l .\github_test.go
(no output — properly formatted)

go build -v ./...
(successful build)

The requestCount variable in several rate limit tests was accessed concurrently by the test goroutine and the background HTTP handler goroutine without synchronization, causing non-deterministic data races detected on Windows CI. Changed requestCount from int to atomic.Int32 using sync/atomic to guarantee memory visibility and atomic increments across goroutines.
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 27, 2026

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.

@mangomaker5
Copy link
Copy Markdown
Contributor Author

I have signed the CLA. Please re-check.

@gmlewis gmlewis changed the title fix: synchronize requestCount in rate limit tests fix: Synchronize requestCount in rate limit tests Mar 27, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.71%. Comparing base (8f1e513) to head (256c00f).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4124   +/-   ##
=======================================
  Coverage   93.71%   93.71%           
=======================================
  Files         211      211           
  Lines       19614    19614           
=======================================
  Hits        18382    18382           
  Misses       1034     1034           
  Partials      198      198           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @mangomaker5!
LGTM.
Meeting.

@gmlewis gmlewis merged commit 4e5486e into google:master Mar 27, 2026
8 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.

Fix data race in TestDo_rateLimit_abortSleepContextCancelled on Windows

2 participants