org.codehaus.xfire.util.jdom.StaxBuilder.buildTree causing infinite loop in 
HashMap.get().
------------------------------------------------------------------------------------------

                 Key: XFIRE-993
                 URL: http://jira.codehaus.org/browse/XFIRE-993
             Project: XFire
          Issue Type: Bug
          Components: Aegis Module
    Affects Versions: 1.2.4
            Reporter: Karthikeyan M.
            Assignee: Dan Diephouse


* Large number (>50) of threads on the server were stuck with infinite loop in 
HashMap.get(). Sample stack trace attached below:

            Thread: http-0.0.0.0-8080-1 : priority:5, demon:true, threadId:54, 
threadState:RUNNABLE, threadLockName:null

                java.util.HashMap.get(HashMap.java:329)
                org.jdom.Namespace.getNamespace(Namespace.java:148)
                
org.jdom.UncheckedJDOMFactory.element(UncheckedJDOMFactory.java:40)
                
org.codehaus.xfire.util.jdom.StaxBuilder.buildTree(StaxBuilder.java:348)
                
org.codehaus.xfire.util.jdom.StaxBuilder.build(StaxBuilder.java:215)
                
org.codehaus.xfire.soap.handler.ReadHeadersHandler.readHeaders(ReadHeadersHandler.java:131)
                
org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:59)
                
org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:98)
                
org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:61)
                
org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
                
org.codehaus.xfire.transport.http.XFireServletController.invoke(XFireServletController.java:278)
                
org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:144)
                
com.yahoo.sm.ws.servlet.XFireRequestProcessor.process(XFireRequestProcessor.java:40)

* HashMap.get() can cause infinite loop, if it is not synchronized correctly. 
(ref: 
http://blogs.opensymphony.com/plightbo/2005/07/hashmapget_can_cause_an_infini.html)

* Xfire ends up calling Namespace.getNamespace() through 
UncheckedJDOMFactory.element(), which is not threadsafe. 

* Namespace.getNamespace() is a static method that gets OR creates the 
Namespace object. When creating the Namespace object, it is cached in an 
internal static HashMap, without any synchronization. When 
Namespace.getNamespace() is called in multiple threads, it corrupts the static 
'namespaces' HashMap in org.jdom.Namespace, resulting in infinite loop in later 
calls.

* This would essentially mean jdom can not be used in an application running 
multiple threads. Can xfire use a safer approach for building header tree?

* one workaround is to synchronize around Namespace instance creation outside 
of jdom and make sure all element creation goes through it. 
Ex:

    public static Element createJDOMElement(JDOMFactory f, String elementName, 
String elemPrefix, String nsURI)
    {
        Namespace ns = initJDOMNamespace(elemPrefix, nsURI);
        return f.element(elementName, ns);
    }

    // workaround to synchronize initialization of static 'namespaces' HashMap 
    // in org.jdom.Namespace class.
    public static synchronized Namespace initJDOMNamespace(String elemPrefix, 
String nsURI)
    {
        return Namespace.getNamespace(elemPrefix, nsURI);
    }

and use createJDOMElement for all jdom element creation inside XFire.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to