You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Art O Cathain (Created) (JIRA)" <ji...@apache.org> on 2012/01/03 16:30:39 UTC

[jira] [Created] (CXF-4006) Possible classloader leak due to ThreadLocal

Possible classloader leak due to ThreadLocal
--------------------------------------------

                 Key: CXF-4006
                 URL: https://issues.apache.org/jira/browse/CXF-4006
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 2.5.1
         Environment: Glassfish
OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
            Reporter: Art O Cathain


org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 

(At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Art O Cathain (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13188415#comment-13188415 ] 

Art O Cathain commented on CXF-4006:
------------------------------------

Yes, that is one of the cases for which we're using CXF (so we're using it as both servlet and client).
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Sergey Beryozkin (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13188412#comment-13188412 ] 

Sergey Beryozkin commented on CXF-4006:
---------------------------------------

Denis, thanks for this info.

Art, in your case, do you also use WebClient in scope of the server web app ?
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Art O Cathain (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13179577#comment-13179577 ] 

Art O Cathain commented on CXF-4006:
------------------------------------

This snippet is from a Yourkit trace to the GC roots, after undeployment:

<class> of org.apache.cxf.jaxrs.ext.MessageContextImpl
value of java.lang.ThreadLocal$ThreadLocalMap$Entry
[482] of java.lang.ThreadLocal$ThreadLocalMap$Entry[512]
table of java.lang.ThreadLocal$ThreadLocalMap
threadLocals of com.sun.grizzly.http.HttpWorkerThread [JNI Global, Stack Local, Thread]  "http-thread-pool-8080(4)"
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Sergey Beryozkin (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13179568#comment-13179568 ] 

Sergey Beryozkin commented on CXF-4006:
---------------------------------------

Hi, the thread local value is released by the runtime after the response has been handled, so no leak will occur.
Do you have some information that shows there could be a leak ?
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Sergey Beryozkin (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13180762#comment-13180762 ] 

Sergey Beryozkin commented on CXF-4006:
---------------------------------------

Hmm, I'm wondering why it seems to be happening on unloading the webapp, this is all cleared Ok during the regular call.
Dan, Benson, do you have any ideas ? 
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Issue Comment Edited] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Sergey Beryozkin (Issue Comment Edited) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13188460#comment-13188460 ] 

Sergey Beryozkin edited comment on CXF-4006 at 1/18/12 2:20 PM:
----------------------------------------------------------------

This has been fixed on the trunk and all the active branches. 
If you can get a chance to try it with the latest snapshot (2.5.x or 2.4.x, etc) then it would help, 
Trunk is building now at https://builds.apache.org/, I will schedule the 2.5.2-SNAPSHOT build next

Cheers, Sergey
                
      was (Author: sergey_beryozkin):
    This has been fixed on the trunk and all the active branches. 
If you can get a chance to try it with the latest snapshot (2.5.x or 2.4.x, etc) then it would help, 
2.5.2-SNAPSHOT is building now at https://builds.apache.org/, 

Cheers, Sergey
                  
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Sergey Beryozkin (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13188460#comment-13188460 ] 

Sergey Beryozkin commented on CXF-4006:
---------------------------------------

This has been fixed on the trunk and all the active branches. 
If you can get a chance to try it with the latest snapshot (2.5.x or 2.4.x, etc) then it would help, 
2.5.2-SNAPSHOT is building now at https://builds.apache.org/, 

Cheers, Sergey
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Denis Delangle (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13189819#comment-13189819 ] 

Denis Delangle commented on CXF-4006:
-------------------------------------

I tried with version 2.5.3-20120120.065637-1 but still have the same error message.
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Denis Delangle (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13188401#comment-13188401 ] 

Denis Delangle commented on CXF-4006:
-------------------------------------

I am having the same kind of issue under Tomcat which is the client, not the server. After undeploying my webapp, I have this message from Tomcat :
{quote}
GRAVE: The web application [/sipbo] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@327958ef]) and a value of type [org.apache.cxf.jaxrs.ext.MessageContextImpl] (value [org.apache.cxf.jaxrs.ext.MessageContextImpl@3cbdcccc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
{quote}

I am creating my client code like this : 
{code:java}
	//I create my delegate instance lazily
	private NotificationService getDelegate() { 
	   if (delegate == null) {
	      delegate = JAXRSClientFactory.create(url, NotificationService.class, new ArrayList<Object>(), true);
	   }
	}

	//I try to destroy the client when shutting down the webapp
	@PreDestroy
	public void cleanResources() {
		WebClient.getConfig(delegate).getBus().shutdown(true);
	}

{code}

After searching with VisualVM, it seems that instances of MesageContextImpl are still stored in a ThreadLocalMessageContext referenced in the static field AbstractResourceInfo.setterProxyMap and in the instance field JAXBElementProvider.mc.

It can be a misuse of the API or it may help solve the bug.
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (CXF-4006) Possible classloader leak due to ThreadLocal

Posted by "Sergey Beryozkin (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-4006?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Beryozkin resolved CXF-4006.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 2.6
                   2.5.3
                   2.4.7
         Assignee: Sergey Beryozkin

Sorry I did not catch the issue earlier; definitely fixed now, a temp regression spanning last 1-2 releases on 2.4.x/2.5.x
The leak should be more or less negligible, but the way to eliminate it with the released CXFs is to register a simple JAXBElementProvider (or/and JSONProvider) only which will override setMessageContext method and make it no-op. 

MessageContext is needed to check for custom STAX handlers and may be Marshaller properties. This all can be managed in the custom provider using PhaseInterceptorChain.getCurrentMessage().

thanks
                
> Possible classloader leak due to ThreadLocal
> --------------------------------------------
>
>                 Key: CXF-4006
>                 URL: https://issues.apache.org/jira/browse/CXF-4006
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.5.1
>         Environment: Glassfish
> OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-61.1.10.4.fc16-x86_64)
>            Reporter: Art O Cathain
>            Assignee: Sergey Beryozkin
>             Fix For: 2.4.7, 2.5.3, 2.6
>
>
> org.apache.cxf.jaxrs.ext.MessageContextImpl is kept in a ThreadLocal for each HTTP request which means when a CXF-servlet-based webapp is undeployed, the webapp's classloader leaks. 
> (At least, I think that's what's going on, I'm not that expert at tracking down memory leaks. Perhaps I have misconfigured something?)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira