-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Load function can be called multiple times for a single cache key before expiration #251
Comments
Hi @wchargin, Thank you for reporting this issue and providing all the necessary stuff for reproducing. You're right, the function is called twice, unless Here is the issue change I found: golang/sync@7f9b162 I'm not sure why this has been done but it seems to cause an issue here because the Maybe @cuonglm who is the author of this change have any explanation on this? Thanks |
This looks similar to the issue described in this GitHub comment. In real-world scenarios, calling Get consecutively is unlikely, so this should be fine (I believe ;)) |
I mean, I filed this issue because I was hitting this in the real world… I couldn't find an adequate workaround, and had to switch away from this caching library altogether. If you don't want to prioritize it, that's your choice, but it is certainly a real issue. |
It looks like issue with scheduler, if you add |
Sleeping hides the problem. Calling |
This is related to #242, but the patch in #243 only partially fixed it. That patch makes sure that the load function can't be called twice for the same cache key at the same time, but doesn't do anything to prevent the load function from being called twice sequentially for the same cache key.
Steps for Reproduction
Here is a short standalone program to demonstrate the issue:
go.mod
And here is a test case that you can add to
loadable_test.go
to reproduce it:Or, comment out the
time.Sleep(time.Millisecond * 10)
in the existing testTestLoadableGetWhenAvailableInLoadFunc
. Sleeping hides the bug!Expected behavior
If
cache.Get("my-key")
is called, completes, and is called again before the cache entry expires, the loader should only be called once.Actual behavior
The loader can be called many times.
Platforms
Tested on both Linux and macOS; I see the same bug in both places.
Versions
github.com/eko/gocache/lib/v4 v4.1.6 h1:5WWIGISKhE7mfkyF+SJyWwqa4Dp2mkdX8QsZpnENqJI=
The text was updated successfully, but these errors were encountered: