Skip to content
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

Caffeine cache concurrency issues #34010

Closed
technical-debt-collector opened this issue Jun 13, 2023 · 3 comments
Closed

Caffeine cache concurrency issues #34010

technical-debt-collector opened this issue Jun 13, 2023 · 3 comments
Labels
area/cache kind/bug Something isn't working

Comments

@technical-debt-collector
Copy link
Contributor

technical-debt-collector commented Jun 13, 2023

Describe the bug

We depend on Caffeine to cache some stuff. The cache is configured with a lockTimeout of 5 secs. However, it doesn't seem like the cache properly locks out concurrent attempts to access the cache (when the cached key is missing) as putting log statements in the cache method indicates it being invoked multiple times.

This causes issues further into the processing of incoming requests in our production and QA environment.
I've been able to reproduce this issue in versions 2.16.5.Final, 2.16.6.Final and 2.16.7.Final.
But I'm not sure to what lengths one should go to fix this as this issue seems to be gone in 3.1.1.Final.

Expected behavior

Only one invocation of the cached method whenever the cache key is missing

Actual behavior

If the cache key is missing, multiple invocations seem to occur in the cache method

How to Reproduce?

Reproducer can be found here: https://github.com/technical-debt-collector/quarkus-cache-repro
The project contains a scheduled method that calls a simple API which in turn will access the cache.

The issue goes away when running with Quarkus 3.1.1.Final.

One can also query the metrics and observe that the cache puts increase faster than expected

Output of uname -a or ver

Linux fedora 6.2.12-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Apr 20 23:38:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "19.0.2" 2023-01-17 OpenJDK Runtime Environment Homebrew (build 19.0.2) OpenJDK 64-Bit Server VM Homebrew (build 19.0.2, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.16.7

Build tool (ie. output of mvnw --version or gradlew --version)

Maven home: /home/olasaeterheitmann/.m2/wrapper/dists/apache-maven-3.8.8-bin/67c30f74/apache-maven-3.8.8 Java version: 17.0.6, vendor: Eclipse Adoptium, runtime: /home/olasaeterheitmann/.sdkman/candidates/java/17.0.6-tem Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "6.2.12-200.fc37.x86_64", arch: "amd64", family: "unix"

Additional information

No response

@technical-debt-collector technical-debt-collector added the kind/bug Something isn't working label Jun 13, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 13, 2023

/cc @gwenneg (cache)

@mkouba
Copy link
Contributor

mkouba commented Jun 13, 2023

But I'm not sure to what lengths one should go to fix this as this issue seems to be gone in 3.1.1.Final.

Yes, we fixed a concurrency problem in quarkus 3.0; see also my comment here.

@technical-debt-collector
Copy link
Contributor Author

Thanks for highlighting this. I'll follow in his tracks and resolve this one. We'll most likely migrate to Quarkus 3 during the summer and can live with the issues for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cache kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants