Skip to content

Conversation

@tsukiyoz
Copy link
Contributor

@tsukiyoz tsukiyoz commented Sep 13, 2025

Description

This PR fixes a bug in the Unbounded.Load() method where the closed flag was not being set to true when the channel was closed.

Problem

In the Load() method, when the condition b.closing && !b.closed is met, the code closes the channel but doesn't update the closed flag. This creates an inconsistent state where:

  • The channel is closed (no more data can be sent)
  • But b.closed remains false

This inconsistency could potentially cause issues in code that relies on the closed flag to determine the buffer's state.

Solution

Added b.closed = true before close(b.c) in the else if branch of the Load() method to ensure the closed flag accurately reflects the buffer's state.

Changes

  • File: internal/buffer/unbounded.go
  • Method: Load()
  • Line: 86
  • Change: Added b.closed = true before closing the channel

Testing

  • ✅ All existing tests pass
  • ✅ No linter errors introduced
  • ✅ The fix ensures consistent state between channel closure and closed flag

Impact

This is a bug fix that improves the correctness of the Unbounded buffer implementation without changing its public API or behavior from a user perspective.

Fixes: #8572

RELEASE NOTES: None

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 13, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: tsukiyoz / name: tsukiyo (2b9161d)

@codecov
Copy link

codecov bot commented Sep 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.84%. Comparing base (8420f3f) to head (2b9161d).
⚠️ Report is 2 commits behind head on master.

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     
Files with missing lines Coverage Δ
internal/buffer/unbounded.go 86.04% <100.00%> (-13.96%) ⬇️

... and 19 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@tsukiyoz tsukiyoz closed this Sep 13, 2025
@tsukiyoz tsukiyoz reopened this Sep 13, 2025
@tsukiyoz
Copy link
Contributor Author

how to add labels to PR 🥲

@tsukiyoz tsukiyoz closed this Sep 13, 2025
@tsukiyoz tsukiyoz reopened this Sep 13, 2025
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.
@tsukiyoz tsukiyoz force-pushed the fix/unbounded-load-closed-flag branch from 9f57ad6 to 2b9161d Compare September 13, 2025 18:31
@eshitachandwani eshitachandwani added this to the 1.76 Release milestone Sep 14, 2025
@eshitachandwani
Copy link
Member

Hey, I have added the labels. I think it is permission setting restricting you to add labels.

@eshitachandwani
Copy link
Member

Adding @arjan-bal as a reviewer.

Copy link
Contributor

@arjan-bal arjan-bal left a 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
Copy link
Contributor

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.

@arjan-bal arjan-bal changed the title fix: set closed flag when closing channel in Load method Sep 15, 2025
@arjan-bal arjan-bal merged commit 83bead4 into grpc:master Sep 15, 2025
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants