cache4k icon indicating copy to clipboard operation
cache4k copied to clipboard

ConcurrentModificationException will be reported when concurrent

Open Jude95 opened this issue 3 years ago • 9 comments

java.util.ConcurrentModificationException
        java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:756)
        java.base/java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:778)
        io.github.reactivecircus.cache4k.RealCache.expireEntries(RealCache.kt:174)
        io.github.reactivecircus.cache4k.RealCache.put(RealCache.kt:120)

Jude95 avatar Jul 07 '22 05:07 Jude95

+1:

java.util.ConcurrentModificationException at 
java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:760) at
java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:782) at
kotlin.collections.CollectionsKt___CollectionsKt.firstOrNull(_Collections.kt:272) at
io.github.reactivecircus.cache4k.RealCache.evictEntries(RealCache.kt:206) at
io.github.reactivecircus.cache4k.RealCache.put(RealCache.kt:140)

Shabinder avatar Oct 26 '22 22:10 Shabinder

I think we need to revert back to using stately which is thread-safe on JVM.

ychescale9 avatar Oct 27 '22 01:10 ychescale9

@ychescale9 will you be making a release anytime soon ?

Shabinder avatar Nov 01 '22 08:11 Shabinder

I'll try to find some time in the coming weeks.

ychescale9 avatar Nov 01 '22 08:11 ychescale9

So I'm having issues with cache4k and ConcurrentModificationExceptions caused by stately on jvm.

Ktor's io.ktor.util.collections.ConcurrentMap seems to be stable, maybe their implementation could be used instead?

luca992 avatar Feb 23 '24 08:02 luca992

Thanks, will look into it.

ychescale9 avatar Feb 23 '24 08:02 ychescale9

+1 for Ktor Utils Collections 😊

hoc081098 avatar Feb 23 '24 09:02 hoc081098

looks like ktor's ConcurrentMap just delegates to ConcurrentHashMap on JVM which I've done in https://github.com/ReactiveCircus/cache4k/pull/39, though there are still some linearizability issues surfaced by Lincheck. Maybe we can land that change now and deal with the remaining issues later as they are not regressions.

ychescale9 avatar Feb 23 '24 10:02 ychescale9

Just released 0.13.0 with ConcurrentHashMap on JVM. Please let me know if this fixes the issue.

ychescale9 avatar Feb 23 '24 12:02 ychescale9