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

miner: Add Work.stateMu to protect Work.state. #178

Merged
merged 1 commit into from
May 15, 2018
Merged

Conversation

benbjohnson
Copy link
Contributor

This pull request should fix the panic caused by:

fatal error: concurrent map iteration and map write

goroutine 81 [running]:
runtime.throw(0xfb0690, 0x26)
	/usr/local/go/src/runtime/panic.go:616 +0x81 fp=0xc495b77408 sp=0xc495b773e8 pc=0x43f661
runtime.mapiternext(0xc495b77718)
	/usr/local/go/src/runtime/hashmap.go:747 +0x55c fp=0xc495b77498 sp=0xc495b77408 pc=0x41d31c
github.com/gochain-io/gochain/core/state.(*StateDB).Copy(0xc4ab406000, 0xc4204e9c00)
	/go/src/github.com/gochain-io/gochain/core/state/statedb.go:491 +0x2eb fp=0xc495b77788 sp=0xc495b77498 pc=0x7fbcdb
github.com/gochain-io/gochain/miner.(*worker).updateSnapshot(0xc420299340)
	/go/src/github.com/gochain-io/gochain/miner/worker.go:523 +0x106 fp=0xc495b777f8 sp=0xc495b77788 pc=0xa47176
github.com/gochain-io/gochain/miner.(*worker).commitNewWork(0xc420299340, 0x10d9e40, 0xc420038040)
	/go/src/github.com/gochain-io/gochain/miner/worker.go:489 +0x10c2 fp=0xc495b77d40 sp=0xc495b777f8 pc=0xa464b2
github.com/gochain-io/gochain/miner.(*worker).update(0xc420299340, 0x10d9e40, 0xc420038040)
	/go/src/github.com/gochain-io/gochain/miner/worker.go:266 +0x71c fp=0xc495b77fc8 sp=0xc495b77d40 pc=0xa4444c
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc495b77fd0 sp=0xc495b77fc8 pc=0x46ee21
created by github.com/gochain-io/gochain/miner.newWorker
	/go/src/github.com/gochain-io/gochain/miner/worker.go:156 +0x4d2

The issue was that after a Miner passes its Work to an Agent, it no longer has the ability to lock a mutex around it. The Miner mutates the Work.state by calling Commit() after the work is returned back to the miner.

Reported upstream: ethereum/go-ethereum#16449

miner/worker.go Outdated
@@ -197,6 +200,8 @@ func (w *worker) pendingQuery(fn func(*state.StateDB) error) error {

w.currentMu.Lock()
defer w.currentMu.Unlock()
w.current.stateMu.RLock()
defer w.current.stateMu.RUnlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this one be a write lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed in eb9e438.

@jmank88 jmank88 merged commit 442ffdc into master May 15, 2018
@jmank88 jmank88 deleted the work-state-mutex branch May 15, 2018 00:49
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

2 participants