Skip to content

Commit

Permalink
create a shallow copy of a map before modifying it (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj authored Feb 21, 2024
1 parent b7bea2c commit e4e6db9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tools/walletextension/wallet_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit e4e6db9

Please sign in to comment.