From 0544bc12c7d256c1648a58804ffca7cdee5380ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Wed, 21 Feb 2024 17:13:00 +0100 Subject: [PATCH] create a shallow copy of a map before modifying it --- tools/walletextension/wallet_extension.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/walletextension/wallet_extension.go b/tools/walletextension/wallet_extension.go index f8625f6a66..242b60ea5a 100644 --- a/tools/walletextension/wallet_extension.go +++ b/tools/walletextension/wallet_extension.go @@ -113,12 +113,18 @@ func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userc // in case of cache hit return the response from the cache if isCacheable { if value, ok := w.cache.Get(key); ok { + // do a shallow copy of the map to avoid concurrent map iteration and map write + returnValue := make(map[string]interface{}) + for k, v := range value { + returnValue[k] = v + } + requestEndTime := time.Now() duration := requestEndTime.Sub(requestStartTime) - w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s, duration: %d ", request.Method, request.Params, hexUserID, value, duration.Milliseconds())) // adjust requestID - value[common.JSONKeyID] = request.ID - return value, nil + returnValue[common.JSONKeyID] = request.ID + w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s, duration: %d ", request.Method, request.Params, hexUserID, returnValue, duration.Milliseconds())) + return returnValue, nil } }