Skip to content
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

fix: data-race when sending a message from consensus/reactor to a peer via p2p.Channel #334

Conversation

shotonoff
Copy link
Collaborator

@shotonoff shotonoff commented Apr 7, 2022

Issue being fixed or feature implemented

After some refactoring in refactor/consensus-reactor-send-broadcast branch.
there was detected data-race between reading data from GO channel and closing it.

What was done?

To solve the data-race issue in p2p.Channel was added an additional select block to check, were channel, a peer, or a reactor close to stopping sending a message

How Has This Been Tested?

Unit-test

Breaking Changes

No

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

@shotonoff shotonoff changed the title fix: data race test reactor invalid block chain lock fix: data-race when sending a message from consensus/reactor to a peer via p2p.Channel Apr 7, 2022
@shotonoff shotonoff closed this Apr 8, 2022
@shotonoff shotonoff closed this Apr 8, 2022
@shotonoff shotonoff reopened this Apr 8, 2022
@shotonoff shotonoff reopened this Apr 8, 2022
@shotonoff shotonoff force-pushed the TD-65-fix-data-race-test-reactor-invalid-block-chain-lock branch from 7f89cfe to e1db9a9 Compare April 8, 2022 08:18
Copy link
Collaborator

@lklimek lklimek left a comment

Choose a reason for hiding this comment

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

LGTM

default:
}
select {
case <-channel.Done():
Copy link
Collaborator

Choose a reason for hiding this comment

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

@@ -662,31 +665,40 @@ func (r *Reactor) sendCommit(ps *PeerState, commit *types.Commit) error {
// If to is nil, message will be broadcasted.
func (r *Reactor) send(ps *PeerState, channel *p2p.Channel, msg proto.Message) error {
select {
case <-channel.Done():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@shotonoff shotonoff left a comment

Choose a reason for hiding this comment

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

made modifications by feedback

@shotonoff shotonoff self-assigned this Apr 11, 2022
…ix-data-race-test-reactor-invalid-block-chain-lock
@shotonoff shotonoff merged commit 160dede into refactor/consensus-reactor-send-broadcast Apr 11, 2022
@shotonoff shotonoff deleted the TD-65-fix-data-race-test-reactor-invalid-block-chain-lock branch April 11, 2022 09:39
shotonoff pushed a commit that referenced this pull request Apr 11, 2022
* refactor(consensus): consolidate redundant code

* refactor(consensus): improve logging in reactor

* refactor(consensus): convert make*Message factory funcs to methods of respective types

* fix: data-race when sending a message from consensus/reactor to a peer via p2p.Channel (#334)

* fix: add an additional select block to check were a chennel / peer or reactor closed

* fix: implement Channel.Send method to safely send messages

* fix: add Channel.Send call for broadcasting

* fix: remove duplication checking of closed channel

* fix: remove first select statement from broadcast method
shotonoff pushed a commit that referenced this pull request May 10, 2022
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.

2 participants