-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Multiple in-flight requests for one key #625
Comments
I won't get a chance to look at this for a few hours, but fwiw you can use |
The mistake is that the expiration check is performed prior to an async check and it does not handle if the entry is still in-flight. I think this occurs in other read paths, like caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java Lines 2418 to 2443 in f924b5c
Previously 2.6.1caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java Lines 727 to 735 in 6be13d6
3.0.4caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java Lines 937 to 943 in 86991da
|
I believe this was accidentally removed when debugging to simulate the overflow issue in #217. The commit's description, changes, and discussions don't appear relevant to this snippet. The test suite passes when it is restored. I will add the appropriate tests to catch this from regressing in the future. I hope to work on it this weekend provide you a release by Monday for both 2.x and 3.x. In the meantime or if that is delayed, you can use the v3.0.4-SNAPSHOT jar on Sonatype's repository or jitpack the |
It's a pleasure to report issues when they are answered. Thanks for the quick response and analysis. |
I am not sure if it is related to this problem, but what is happening to me is that sometimes my loader is never called again, because Node still think it is running. Debugger says that future is complete (it also returns immediately when got from cache) as well as my job status of the async loader. But Node in the cache still has writeTime set to large value (200 years ahead - com.github.benmanes.caffeine.cache.Async.ASYNC_EXPIRY) which prevents expiration. That future time from what I understand is marker that task is still running. Do you think it is same issue? |
That would indicate that the callback is never invoked when the future completed. In this issue the future was prematurely replaced with a new execution, but when that replacement completed it's handler should successfully update the caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java Lines 189 to 217 in 86991da
|
OK I have found the problem. It actually works fine, but thread that loads asynchronously is then used to "complete" future and notify. In my case I convert future to Mono in reactor and it steals thread to execute requests. This go back to the cache again and cycles (I do retry there). That as a result is actually working, but on incorrect place and cannot get back. Caffeine is then still thinking future is working on result even if it finished and is still in notify. Sorry for confusion. |
This restores the behavior that was accidentally removed in v2.6.2 and adds unit tests to assert it going forward.
This restores the behavior that was accidentally removed in v2.6.2 and adds unit tests to assert it going forward.
This restores the behavior that was accidentally removed in v2.6.2 and adds unit tests to assert it going forward.
I did not get to working on this today, where the intent was to backport to v2 and release. I will see what I can do over the week, but given the holidays and an ongoing investigations for the root cause of f143764, the goal for a release is delayed until the next weekend. The jitpack or snapshot jars pass our CI testing and should be stable if you'd prefer something earlier. @koldat it sounds like you ran into the surprising fact that CompletableFuture's ordering of dependent actions is in LIFO order for efficiency, whereas one might naturally expect FIFO execution. Unfortunately we cannot work around this quirk without worse effects. If we instead returned the |
Sorry that this took longer than expected. This is released in v2.9.3 and v3.0.5. |
Demo project: https://github.com/pertu/caffeine-async-loading-in-flight-ignored (
mvn test
should work).Test from the demo project (simplified):
See also: #297
Edit: tested version 3.0.4 and 2.9.2, result is the same
Edit 2: the test above is timing-dependent and doesn't always fail
actual test in demo project runs the code above in loop and usually fails on the second iteration on my machine
The text was updated successfully, but these errors were encountered: