From b5a3d8e82a8ba5e41e52d779345f2179ddb8a4af Mon Sep 17 00:00:00 2001 From: Piers Powlesland Date: Fri, 1 Oct 2021 15:50:36 +0100 Subject: [PATCH] trie: Fix concurrent map access on trie.dirties The dirties map of trie.Database was not read protected inside the commit function, since the trie.Database is called from many go-routines this sometimes lead to concurrent map read and write errors. The solution is to read lock over trie.dirties in commit --- trie/database.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/trie/database.go b/trie/database.go index f140a56642f..6bdd89c6682 100644 --- a/trie/database.go +++ b/trie/database.go @@ -755,10 +755,15 @@ func (db *Database) Commit(node common.Hash, report bool, callback func(common.H // commit is the private locked version of Commit. func (db *Database) commit(hash common.Hash, batch ethdb.Batch, uncacher *cleaner, callback func(common.Hash)) error { // If the node does not exist, it's a previously committed node + + db.lock.RLock() node, ok := db.dirties[hash] if !ok { + db.lock.RUnlock() return nil } + db.lock.RUnlock() + var err error node.forChilds(func(child common.Hash) { if err == nil {