google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

broken thread safety in Mapper.java #374

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB)

1.0.0 snapshot, but error exists in TRUNK

http://code.google.com/p/morphia/source/browse/trunk/morphia/src/main/java/com/g
oogle/code/morphia/mapping/Mapper.java#165

The code linked above uses a non-thread-safe HashSet and assigns it in a manner 
prone to a race condition. This is currently causing 100% cpu hung threads in a 
multithreaded environment on the HashMap.put on line 170 for me.

Original issue reported on code.google.com by sc...@relateiq.com on 8 Feb 2012 at 5:44

GoogleCodeExporter commented 9 years ago
Just committed your fix. http://code.google.com/p/morphia/source/detail?r=1803

Original comment by scotthernandez on 8 Feb 2012 at 6:11

GoogleCodeExporter commented 9 years ago
not fixed, the bigger issue is the use of a vanilla HashSet, it needs something 
concurrent as well.

Collections.newSetFromMap(new ConcurrentHashMap<MappedClass, Boolean>());

also, you need to use the return value of putIfAbsent if it is non-null, as it 
means something was already there (due to yet another race condition)

Original comment by sc...@relateiq.com on 8 Feb 2012 at 6:49

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1804.

Original comment by scotthernandez on 8 Feb 2012 at 7:03