-
Notifications
You must be signed in to change notification settings - Fork 4.6k
internal/buffer: set closed flag when closing channel in the Load method #8575
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
internal/buffer: set closed flag when closing channel in the Load method #8575
Conversation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8575 +/- ##
==========================================
- Coverage 80.91% 80.84% -0.07%
==========================================
Files 413 413
Lines 40751 40754 +3
==========================================
- Hits 32972 32947 -25
- Misses 6155 6178 +23
- Partials 1624 1629 +5
🚀 New features to boost your workflow:
|
|
how to add labels to PR 🥲 |
The Load method was closing the channel when b.closing && !b.closed but was not setting the b.closed flag to true. This could lead to inconsistent state where the channel is closed but the closed flag is still false. RELEASE NOTES: * internal/buffer: Fixed inconsistent state where closed flag was not set when channel was closed in Load method.
9f57ad6 to
2b9161d
Compare
|
Hey, I have added the labels. I think it is permission setting restricting you to add labels. |
|
Adding @arjan-bal as a reviewer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix.
| default: | ||
| } | ||
| } else if b.closing && !b.closed { | ||
| b.closed = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bug could have caused a panic if Load() was called after the channel is already closed once. I audited all the usages of Load() and verified that they either use the val, ok := <- ch.Load() syntax or a range based for loop to avoid calling Load() on a closed channel.
Description
This PR fixes a bug in the
Unbounded.Load()method where theclosedflag was not being set totruewhen the channel was closed.Problem
In the
Load()method, when the conditionb.closing && !b.closedis met, the code closes the channel but doesn't update theclosedflag. This creates an inconsistent state where:b.closedremainsfalseThis inconsistency could potentially cause issues in code that relies on the
closedflag to determine the buffer's state.Solution
Added
b.closed = truebeforeclose(b.c)in theelse ifbranch of theLoad()method to ensure the closed flag accurately reflects the buffer's state.Changes
internal/buffer/unbounded.goLoad()b.closed = truebefore closing the channelTesting
Impact
This is a bug fix that improves the correctness of the
Unboundedbuffer implementation without changing its public API or behavior from a user perspective.Fixes: #8572
RELEASE NOTES: None