-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Failing TestCache_MaxCacheSizeParallel/LruCache #28
Comments
Hey team! I mean the c.backend.Add(key, data)
if s, ok := data.(Sizer); ok {
atomic.AddInt64(&c.currentSize, int64(s.Size()))
if c.maxCacheSize > 0 && atomic.LoadInt64(&c.currentSize) > c.maxCacheSize {
for atomic.LoadInt64(&c.currentSize) > c.maxCacheSize {
c.backend.RemoveOldest()
}
}
} If the requirement is that none of the client goroutines should ever observe Possible scenario could be:
Eventually, when execution of all the goroutines is complete, the cache will converge to the correct state, but during the execution it can fluctuate pretty significantly. I ran the tests locally and in all cases the test fails at line #229, which is inside of the goroutine. As the goroutines can observe the fluctuations, you probably should not assume any upper limit (the If you are ok with the fluctuations of the actual cache size, then I would suggest to remove the What do you think? |
@chychkan, thanks a lot for the investigation! @umputun what do you think about removing problematic test line and acknowledging that the size limit for the cache has a loose guarantee? I don't see the reason to sacrifice the speed to enforce the limit and would vote for altering the text, as proposed by Oleksandr. |
Fixes flaps in TestCache_MaxCacheSizeParallel, resolves #28
With probability higher than 20% locally and than 50% on GitHub Actions,
TestCache_MaxCacheSizeParallel/LruCache
fails with race condition. It's seen asLruCache.currentSize
wrong values \ concurrent changes despite the fact that all changes are done usingatomic.AddInt64
andatomic.LoadInt64
.Example in GitHub Actions
If somebody would be able to fix code in a way it won't fail, it would be great.
The text was updated successfully, but these errors were encountered: