-
Notifications
You must be signed in to change notification settings - Fork 534
fix race condition on ObjectLRU #544
fix race condition on ObjectLRU #544
Conversation
Codecov Report
@@ Coverage Diff @@
## master #544 +/- ##
==========================================
- Coverage 78.07% 77.48% -0.59%
==========================================
Files 129 129
Lines 9792 9798 +6
==========================================
- Hits 7645 7592 -53
- Misses 1316 1388 +72
+ Partials 831 818 -13
Continue to review full report at Codecov.
|
plumbing/cache/object_test.go
Outdated
for i := 0; i < 1000; i++ { | ||
wg.Add(1) | ||
go func(i int) { | ||
s.c.Put(newObject(fmt.Sprint(i), FileSize(i))) |
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.
Do we also want to exercise the other operations that require synchronization? Like Get and Clear?
Signed-off-by: Miguel Molina <[email protected]>
ef35f91
to
3fd3988
Compare
@orirawlings amended with usage of |
@@ -67,6 +72,9 @@ func (c *ObjectLRU) Put(obj plumbing.EncodedObject) { | |||
// Get returns an object by its hash. It marks the object as used. If the object | |||
// is not in the cache, (nil, false) will be returned. | |||
func (c *ObjectLRU) Get(k plumbing.Hash) (plumbing.EncodedObject, bool) { | |||
c.mut.Lock() |
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.
Maybe we can use a RWLock? as suggested at: https://blog.golang.org/go-maps-in-action
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.
Get
mutates the state in c.ll.MoveToFront(ee)
, that's why I used a Mutex
instead of a RWMutex
With concurrent usage, it could lead to a
concurrent map access
panic on runtime.Sadly, the test only adds value with
-race
enabled. If you have any idea how to get that panic on the test, it would improve its robustness.