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

core: Synchronize wait group access in blockchain #23673

Closed

Conversation

piersy
Copy link
Contributor

@piersy piersy commented Oct 1, 2021

When using a wg Add is intended to be called before Wait, calling Add
and Wait concurrently leads to data races.

See a simple example of this problem here:
golang/go#23842

The blockchain calls wg.Add in many exported methods such as chain
insert methods and it seems highly unlikely that they will be called by
the same goroutine that calls Stop (where wg.Wait is called), so to
avoid data races on shutdown the acesses to Add and Wait need to be
synchronized.

The solution here is to lock over calls to Add and Wait.

When using a wg Add is intended to be called before Wait, calling Add
and Wait concurrently leads to data races.

The blockchain calls wg.Add in many exported methods such as chain
insert methods and it seems highly unlikely that they will be called by
the same goroutine that calls Stop (where wg.Wait is called), so to
avoid data races on shutdown the acesses to Add and Wait need to be
synchronized.

The solution is to lock over calls to Add and Wait.

A golang issue with more details about this problem
golang/go#23842
@holiman
Copy link
Contributor

holiman commented Oct 1, 2021

A different fix is to remove the silly waitgroups: #22853 . If you're looking into these things, I'd appreciate if you take a look at that PR, if it seems ok to you.

@fjl
Copy link
Contributor

fjl commented Oct 4, 2021

I strongly prefer #22853 over this PR.

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.

None yet

3 participants