[channel] Fix race condition on channel.Ready.Reset()#446
Merged
liran-funaro merged 1 commit intohyperledger:mainfrom Mar 19, 2026
Merged
[channel] Fix race condition on channel.Ready.Reset()#446liran-funaro merged 1 commit intohyperledger:mainfrom
liran-funaro merged 1 commit intohyperledger:mainfrom
Conversation
Contributor
|
Please add root cause in all PR description to save review time. |
Contributor
|
An example #410 It was generated by Bob. |
00a2efd to
0669b16
Compare
Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
0669b16 to
b1a49aa
Compare
Contributor
Author
@cendhu done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
Description
Root cause: The
Ready.Reset()method was experiencing a race condition due to non-atomic struct field replacement. The original implementation used*r = *NewReady()to reset the struct, which performs a multi-step memory copy operation that replaces all fields (channelsready,closed, andonce). This struct copy is not atomic.Concurrently, other goroutines calling
WaitForReady()orWaitForAllReady()would read from the same channel fields (r.readyandr.closed) via select statements. This created a classic data race where one goroutine was writing to struct fields while others were simultaneously reading from them.Race scenario:
Reset()and begins copying new struct fields (non-atomic multi-step operation)WaitForReady()and attempts to readr.readyorr.closedchannelsThe fix: Uses atomic pointer indirection by moving channels into an inner
readystruct and storing only anatomic.Pointer[ready]in the outerReadystruct. This enables atomic swapping of the entire internal state viaCompareAndSwap(), eliminating the race condition while maintaining the same external API.Related issues