From c5e323b25cc1547b7da457769f9445e7228a105c Mon Sep 17 00:00:00 2001 From: Minh Doan <40258599+mikedoan@users.noreply.github.com> Date: Sun, 29 Mar 2020 13:20:24 -0700 Subject: [PATCH] add lock to protection storage dump (#2624) --- api/service/explorer/storage.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/service/explorer/storage.go b/api/service/explorer/storage.go index 325802c19..a8fb9eea3 100644 --- a/api/service/explorer/storage.go +++ b/api/service/explorer/storage.go @@ -30,7 +30,8 @@ var once sync.Once // Storage dump the block info into leveldb. type Storage struct { - db *leveldb.DB + db *leveldb.DB + lock sync.Mutex } // GetStorageInstance returns attack model by using singleton pattern. @@ -72,6 +73,8 @@ func (storage *Storage) GetDB() *leveldb.DB { // Dump extracts information from block and index them into lvdb for explorer. func (storage *Storage) Dump(block *types.Block, height uint64) { + storage.lock.Lock() + defer storage.lock.Unlock() if block == nil { return }