-
Notifications
You must be signed in to change notification settings - Fork 20.8k
common/lru: fix race in lru #26164
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
Merged
Merged
common/lru: fix race in lru #26164
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariusVanDerWijden
approved these changes
Nov 11, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
yperbasis
added a commit
to ledgerwatch/erigon-lib
that referenced
this pull request
Nov 14, 2022
[simplelru](https://github.com/hashicorp/golang-lru/tree/master/simplelru) is not thread safe. During the `Get` operation, the recentness of the accessed item is updated, so it is not a pure read-operation. Therefore, the mutex we need to protect the LRUs in txpool is a full mutex, not `RLock`. See erigontech/erigon#4679 (comment) and ethereum/go-ethereum#26164. Also, RWMutex has a performance overhead compared with the vanilla one (see, for example, golang/go#38813). Kudos to Martin Swende for pointing to the issue.
lochjin
pushed a commit
to lochjin/go-ethereum
that referenced
this pull request
Nov 19, 2022
This fixes a problem in the SizeConstrainedLRU. The SCLRU uses an underlying simple lru which is not thread safe. During the Get operation, the recentness of the accessed item is updated, so it is not a pure read-operation. Therefore, the mutex we need is a full mutex, not RLock. This PR changes the mutex to be a regular Mutex, instead of RWMutex, so a reviewer can at a glance see that all affected locations are fixed. (cherry picked from commit 8334b5f)
dindinw
added a commit
to Qitmeer/go-ethereum
that referenced
this pull request
Nov 19, 2022
common/lru: fix race in lru (ethereum#26164)
lochjin
pushed a commit
to lochjin/go-ethereum
that referenced
this pull request
Nov 30, 2022
This fixes a problem in the SizeConstrainedLRU. The SCLRU uses an underlying simple lru which is not thread safe. During the Get operation, the recentness of the accessed item is updated, so it is not a pure read-operation. Therefore, the mutex we need is a full mutex, not RLock. This PR changes the mutex to be a regular Mutex, instead of RWMutex, so a reviewer can at a glance see that all affected locations are fixed. (cherry picked from commit 8334b5f)
shekhirin
pushed a commit
to shekhirin/go-ethereum
that referenced
this pull request
Jun 6, 2023
This fixes a problem in the SizeConstrainedLRU. The SCLRU uses an underlying simple lru which is not thread safe. During the Get operation, the recentness of the accessed item is updated, so it is not a pure read-operation. Therefore, the mutex we need is a full mutex, not RLock. This PR changes the mutex to be a regular Mutex, instead of RWMutex, so a reviewer can at a glance see that all affected locations are fixed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a problem in the
SizeConstrainedLRU
. The SCLRU uses an underlying simple lru which is not thread safe.During the
Get
operation, the recentness of the accessed item is updated, so it is not a pure read-operation. Therefore, the mutex we need is a full mutex, not RLock.This PR changes the mutex to be a regular
Mutex
, instead ofRWMutex
, so a reviewer can at a glance see that all affected locations are fixed.Fixes: #26163