Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a shallow copy of a map before modifying it #1813

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading