From cd7e08ec0f9929c43ecf79917d52a1cbede639eb Mon Sep 17 00:00:00 2001 From: zjubfd <296179868@qq.com> Date: Mon, 14 Mar 2022 18:53:03 +0800 Subject: [PATCH] fix race condition on preimage --- trie/database.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trie/database.go b/trie/database.go index b6a3154d48..649af6dbf9 100644 --- a/trie/database.go +++ b/trie/database.go @@ -722,17 +722,18 @@ func (db *Database) Commit(node common.Hash, report bool, callback func(common.H batch := db.diskdb.NewBatch() // Move all of the accumulated preimages into a write batch + db.lock.RLock() if db.preimages != nil { rawdb.WritePreimages(batch, db.preimages) // Since we're going to replay trie node writes into the clean cache, flush out // any batched pre-images before continuing. if err := batch.Write(); err != nil { + db.lock.RUnlock() return err } batch.Reset() } // Move the trie itself into the batch, flushing if enough data is accumulated - db.lock.RLock() nodes, storage := len(db.dirties), db.dirtiesSize db.lock.RUnlock()