Skip to content

core: Synchronize wait group access in blockchain#23673

Closed
piersy wants to merge 1 commit intoethereum:masterfrom
piersy:bugfix-data-race-in-blockchain
Closed

core: Synchronize wait group access in blockchain#23673
piersy wants to merge 1 commit intoethereum:masterfrom
piersy:bugfix-data-race-in-blockchain

Conversation

@piersy
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

3 participants