-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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:
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);
}