Skip to content

Issue with Jetty virtual threads enabled and Cache #220

@diegoatpitch

Description

@diegoatpitch

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

Hello. We are trying to enable Jetty support for Virtual Threads and we hit an issue with GuavaCachedJwkProvider. It uses com.google.common.cache.LocalCache which is synchronized, causing thread pinning.

Reproduction

I found this by enabling this JVM option -Djdk.tracePinnedThreads=full, which produced the following stack trace (clamped to remove internal namespaces)

    com.auth0.jwk.UrlJwkProvider.getJwks(UrlJwkProvider.java:136)
    com.auth0.jwk.UrlJwkProvider.getAll(UrlJwkProvider.java:145)
    com.auth0.jwk.UrlJwkProvider.get(UrlJwkProvider.java:163)
    com.auth0.jwk.RateLimitedJwkProvider.get(RateLimitedJwkProvider.java:28)
    com.auth0.jwk.GuavaCachedJwkProvider.lambda$get$0(GuavaCachedJwkProvider.java:62)
    com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4860)
    com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3551)
    com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2302)
    com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2177) <== monitors:1
    com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2068)
    com.google.common.cache.LocalCache.get(LocalCache.java:3986)
    com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4855)
    com.auth0.jwk.GuavaCachedJwkProvider.get(GuavaCachedJwkProvider.java:62)

Additional context

There is this issue in Guava repository, but it's closed as "won't fix" as they suggest using Caffeine for caching instead.

For reference, Spring has replaced Guava Caching with Caffeine: spring-projects/spring-framework#18370

jwks-rsa version

0.22.1

Java version

21

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis points to a verified bug in the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions