Skip to content

fix(ring): serialize capacity and shutdown checks - #176

Merged
appleboy merged 1 commit into
golang-queue:masterfrom
bensynapse:fix-ring-capacity-lock
Oct 31, 2026
Merged

appleboy merged 1 commit into
golang-queue:masterfrom
bensynapse:fix-ring-capacity-lock

Conversation

@bensynapse

Copy link
Copy Markdown
Contributor

I run Live Tennis API.

WithQueueSize(2) can admit four jobs when producers submit at the same time. Ring.Queue checks capacity before locking the buffer.
Ring.Request also reads count without locking during shutdown. Concurrent readers can trigger a data race and return ErrNoTaskInQueue after closure.

Move both checks inside the existing mutex so they share the lock with buffer updates. Add concurrent capacity and shutdown drain tests.

make test passes with race detection on Go 1.26.8 and 1.27.0. The focused regressions pass 50 runs with -race.
make lint, go build ./... and go vet ./... pass. Both example modules build and execute successfully.

@appleboy

Copy link
Copy Markdown
Member

@bensynapse Thanks.

@codecov-commenter

codecov-commenter commented Oct 31, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.73%. Comparing base (cdbf1cb) to head (d4c965a).
⚠️ Report is 86 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #176      +/-   ##
==========================================
+ Coverage   91.29%   92.73%   +1.44%     
==========================================
  Files           7        8       +1     
  Lines         402      413      +11     
==========================================
+ Hits          367      383      +16     
- Misses         28       30       +2     
+ Partials        7        0       -7     
Flag Coverage Δ
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.22 ?
go-1.26 90.31% <100.00%> (?)
go-1.27 92.81% <100.00%> (?)
macos-latest ?
ubuntu-latest 92.73% <100.00%> (+1.69%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@appleboy
appleboy merged commit 9721be6 into golang-queue:master Oct 31, 2026
6 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.

3 participants