From 34aa5df84de0d56ae6d6bca08c36c72752c37e6b Mon Sep 17 00:00:00 2001 From: Austin Roberts Date: Mon, 18 Oct 2021 17:06:16 -0500 Subject: [PATCH] Use locks to prevent concurrent map accesses --- core/rawdb/plugin_hooks.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/rawdb/plugin_hooks.go b/core/rawdb/plugin_hooks.go index 887c3015a..40466be93 100644 --- a/core/rawdb/plugin_hooks.go +++ b/core/rawdb/plugin_hooks.go @@ -5,13 +5,17 @@ import ( "github.com/ethereum/go-ethereum/plugins" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" + "sync" ) var ( freezerUpdates map[uint64]map[string]interface{} + lock sync.Mutex ) func PluginTrackUpdate(num uint64, kind string, value interface{}) { + lock.Lock() + defer lock.Unlock() if freezerUpdates == nil { freezerUpdates = make(map[uint64]map[string]interface{}) } update, ok := freezerUpdates[num] if !ok { @@ -21,11 +25,6 @@ func PluginTrackUpdate(num uint64, kind string, value interface{}) { update[kind] = value } -func PluginResetUpdate(num uint64) { - delete(freezerUpdates, num) -} - - func pluginCommitUpdate(num uint64) { if plugins.DefaultPluginLoader == nil { log.Warn("Attempting CommitUpdate, but default PluginLoader has not been initialized") @@ -35,6 +34,8 @@ func pluginCommitUpdate(num uint64) { } func PluginCommitUpdate(pl *plugins.PluginLoader, num uint64) { + lock.Lock() + defer lock.Unlock() if freezerUpdates == nil { freezerUpdates = make(map[uint64]map[string]interface{}) } defer func() { delete(freezerUpdates, num) }() update, ok := freezerUpdates[num]