TimeAndSpaceIO / SmoothieMap

A gulp of low latency Java
295 stars 30 forks source link

ConcurrentModificationException on remove() #8

Closed itsdax closed 4 years ago

itsdax commented 4 years ago

Experiencing rare CMEs on map.remove(object) with version 2.0.1 after upgrading from 1.3 The map is only within the scope of a single thread and is not being iterated.

I've added a shared lock for all put/remove/contains operations on the map but was still getting CME.

I'm making a large number of put, remove, and contains operations in a small time frame (thousands of calls in a few ms), which may be what's causing it.

Below is the exception. I'll pull up a snippet for reproducing this issue once I get the chance. The test cases I made was not able to reproduce this issue. I may have to create a subset of my original data set for this.

Using jdk1.8.0_231

Exception in thread "JavaFX Application Thread" java.util.ConcurrentModificationException
    at io.timeandspace.smoothie.SmoothieMap.checkModCountOrThrowCme(SmoothieMap.java:1242)
    at io.timeandspace.smoothie.SmoothieMap.tryShrink3(SmoothieMap.java:3771)
    at io.timeandspace.smoothie.SmoothieMap.tryShrink2(SmoothieMap.java:3674)
    at io.timeandspace.smoothie.SmoothieMap.tryShrink1(SmoothieMap.java:3632)
    at io.timeandspace.smoothie.SmoothieMap.removeAtSlot(SmoothieMap.java:3575)
    at io.timeandspace.smoothie.SmoothieMap.removeImpl(SmoothieMap.java:1935)
    at io.timeandspace.smoothie.SmoothieMap.remove(SmoothieMap.java:1389)
itsdax commented 4 years ago

Update: Using SmoothieMap.<Node, Object>newBuilder().optimizeFor(LOW_GARBAGE).build(); completely resolves the issue for me. Weird

leventov commented 4 years ago

Thanks for reporting. I think this issue should be fixed in the new version 2.0.2.