puniverse / quasar

Fibers, Channels and Actors for the JVM
http://docs.paralleluniverse.co/quasar/
Other
4.56k stars 575 forks source link

Warning "Duplicate class entries" caused by instrumentation threads interleaving #286

Open mkit opened 7 years ago

mkit commented 7 years ago

When starting our application we see those warnings about duplicate class entries: [quasar] WARNING: Duplicate class entries with different data for class: [ClassName] This warning is printed in the recordSuspendableMethods method, line 262. After debugging the instrumentation process and putting a breakpoint at that line we see the following stack traces:

screen shot 2017-08-23 at 10 32 48

From the code above you see, that you get this warning only if the ClassEntry instance already exists in the classes map and if it is different (considering references) than the new one.

screen shot 2017-08-23 at 10 33 29

The stack trace above indicates that the ClassEntry instance is not present for the className in the classes map at the time of the if (entry == null) condition evaluation at line 319.

screen shot 2017-08-23 at 10 34 00

The above snippet is to confirm this further.

Therefore, there is a race condition in the classes map access by different threads. Depending on the intended behaviour there could be (at least) 3 solutions that we would like to suggest:

1) In the first snippet you see that both the oldEntry and the entry are the same in terms of data and thus can be possibly compared based on the equal method basis, instead of == reference comparison.

2) extend the synchronized block in the checkClass method. This would possibly affect performance.

3) reduce the log level to DEBUG or even TRACE (if combined with solution 1)).

mikehearn commented 7 years ago

Thanks Michal.

mikehearn commented 7 years ago

I can't reproduce this anymore after upgrading to 0.7.9 but I'll keep trying, as it is tricky to reproduce. As this code doesn't seem to have changed lately I suspect the race is still there but something has changed timing-wise to make it show up less.