Skip to content

JdbcMetadataStore putIfAbsent may stuck in while loop on MySQL database. #10847

@jurek7

Description

@jurek7

In what version(s) of Spring Integration are you seeing this issue?

6.5.7

Describe the bug

I observed that JdbcMetadataStore stuck in while loop on my production environment(2 service instances) in the following method:

https://github.com/spring-projects/spring-integration/blob/main/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStore.java#L227

Issue may happen where two processes(or threads) will access putIfAbsent method at the same time and one of them was able to insert record to database.

Issue is related to the fact that MySQL database is using REPEATABLE READ isolation level and if one process(or thread) successfully insert record to database the other will not be able to read it thus it will stuck in while loop forever.

To Reproduce

Run two services with MySQL database and default transaction isolation level.

Expected behavior

Should work in distributed environment and MySQL database.

Sample

I was able to simulate issue with tests containers and unit tests but I am not able to copy this code here due to strict security policy in company. Pseudo code to reproduce problem:

for(int idx = 0; i<100; i++) {
exec = Executors.newFixedThreadPool(2)
futures = new ArrayList(2)
futures.add(CompletableFuture.supplyAsync(() -> metadataStore.putIfAbsent("testKey" + idx, "testValue")), exec)
futures.add(CompletableFuture.supplyAsync(() -> metadataStore.putIfAbsent("testKey" + idx, "testValue")), exec)
CompletableFuture.allOff(futures).join();
exec.shutdown();
exec.awaitTermination(1, TimeUnit.SECONDS);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions