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

BoundValueOperations not visible when initializing boundValueOps on Fork/Join pool #2920

Closed
app2smile opened this issue May 31, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@app2smile
Copy link

app2smile commented May 31, 2024

environment:

jdk21
spring boot 3.2.6
caffeine

Describe the bug:

org.springframework.data.redis.core.BoundValueOperations referenced from a method is not visible from class loader: 'app'

When I ran the following code inside the Docker container, an error occurred I am unable to reproduce this issue when running in a local environment I don't know what caused this problem

@SpringBootApplication
public class CaffeineDemoApplication implements CommandLineRunner {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void run(String... args) throws Exception {
        LoadingCache<String, String> cache = Caffeine.newBuilder()
                .refreshAfterWrite(Duration.ofSeconds(5))
                .build(key -> {
                    // do something
                    // ...
                    stringRedisTemplate.boundValueOps(key).set("1");
                    // ...
                    return "any";
                });
        cache.get("1");

        // error
        // java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: org.springframework.data.redis.core.BoundValueOperations referenced from a method is not visible from class loader: 'app'
        cache.refresh("1");
    }

    public static void main(String[] args) {
        SpringApplication.run(CaffeineDemoApplication.class, args);
    }
}

To Reproduce:

  1. modify the Redis configuration in application.yml
  2. maven install
  3. docker build -t demo:v1 .
  4. docker run --rm --net=host demo:v1

demo.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 31, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 31, 2024
@mp911de mp911de changed the title BoundValueOperations referenced from a method is not visible from class loader: 'app' BoundValueOperations not visible when initializing boundValueOps on Fork/Join pool May 31, 2024
@mp911de
Copy link
Member

mp911de commented May 31, 2024

Thanks for the report. The issue is caused by Spring Data Redis relying on the contextual class loader. Running code on the Fork/Join pool resorts to the app class loader that was used to bootstrap the Spring Boot loader. Spring Boot uses a different class loader that has access to the bundled jars and so class loading fails.

We need to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants