Mantis - Resin
Viewing Issue Advanced Details
1588 minor sometimes 01-26-07 04:15 04-06-07 15:16
bjornm  
ferg  
normal  
closed 3.0.20  
fixed  
none    
none 3.1.1  
0001588: Hessian SerializerFactory HashMaps involved in 100% CPU infinite loop?
During load tests to HessianServlets, we've sometimes experienced that the jvm would hang with 100% cpu. Thread dumps showed many threads were busy in HashMap.get:

"http-0.0.0.0-8080-8" daemon prio=1 tid=0x465bfbd8 nid=0x64e2 runnable [0x3f371000..0x3f3721b0]
        at java.util.HashMap.get(HashMap.java:346)
        at com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java)
        at com.caucho.hessian.io.HessianOutput.writeObject(HessianOutput.java:315)
        at com.caucho.hessian.io.JavaSerializer$FieldSerializer.serialize(JavaSerializer.java:242)
        at com.caucho.hessian.io.JavaSerializer.writeObject10(JavaSerializer.java:175)
        at com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:157)
        at com.caucho.hessian.io.HessianOutput.writeObject(HessianOutput.java:317)
        at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:172)
        at com.caucho.hessian.server.HessianServlet.service(HessianServlet.java:365)

A look at SerializerFactory shows it uses a set of hashmaps which are not synchronized:

  private HashMap _cachedSerializerMap;
  private HashMap _cachedDeserializerMap;
  private HashMap _cachedTypeDeserializerMap;

My guess is that if a HessianServlet receives many simultaneous calls during startup (when the maps are empty), concurrent read and write to the _cachedSerializerMap could cause this behavior. If this is the case, I suggest wrapping them in synchronizers:

_cachedDeserializerMap = Collections.synchronizedMap(new HashMap(8));

I have however been unable to reproduce this in some simple tests. Maybe someone who is more familiar with the code could advise.
About infinite loops in unsynchronized HashMaps:
http://blogs.opensymphony.com/plightbo/2005/07/hashmapget_can_cause_an_infini.html [^]

There are no notes attached to this issue.