You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jose María Zaragoza <de...@gmail.com> on 2014/01/10 12:20:20 UTC

WS-Addressing + CXF 2.7.8 memory leak

Hello:

I'm using CXF 2.7.8 and JAX-WS  to create a SOAP webservice

This webservice calls another webservice who requieres WS-Addressing

So, I declare a simple JAX-WS client with WS-Addressing enabled


 <jaxws:client id="client"
                  serviceClass="com.external.WSPortType"
                  address="http://extermal.com/Process.jpd"
                  bindingId="http://schemas.xmlsoap.org/wsdl/soap/http">

         <jaxws:features>
             <wsa:addressing xmlns:wsa="http://cxf.apache.org/ws/addressing"/>
       </jaxws:features>
</jaxws:client>


I inject this bean into my webservice implementor with

@Autowired
WSPortType client;

So, it's shared by all requests and I think is thread-safe 'in practice'
(http://cxf.apache.org/faq.html#FAQ-AreJAX-WSclientproxiesthreadsafe?)

This client sends messages like

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Action xmlns="http://www.w3.org/2005/08/addressing">process</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:aebe3485-07bc-4af7-a3a5-c1df7af15adb
</MessageID>
<To xmlns="http://www.w3.org/2005/08/addressing">http://extermal.com/Process.jpd
</To>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
</soap:Header>
<soap:Body>
<process xmlns="urn:com:external:types">
<phone>34606958413</phone>
<filterParams>
<field>data</field>
</filterParams>
</process>
</soap:Body>
</soap:Envelope>

and it receives the response correctly ( with the right MessageID )


Well, this is the scenario.
In this case, JVM memory heap increases all time and grows up until OOM
Looking at jvisualm I see a lot of string objects being used by
WS-addressing library
If I comment WS-Addressing feature , all works fine and the memory
heap's behaviour is normal.

What is wrong ? Any ideas ?
If you need more data or other test, no problem

Thanks and regads

Re: WS-Addressing + CXF 2.7.8 memory leak

Posted by David Karlsen <da...@gmail.com>.
The latter sounds reasonable to make clients aware of violation of
protocol, but probably as a configurable option ("strict" mode?). Spec does
not tell how server should behave in these cases?
14. jan. 2014 00:21 skrev "Daniel Kulp" <dk...@apache.org> følgende:

>
> On Jan 13, 2014, at 2:52 PM, Jose María Zaragoza <de...@gmail.com>
> wrote:
>
> > 2014/1/13 Daniel Kulp <dk...@apache.org>:
> >>
> >> These are showing that the RelatesTo header wasn’t there or similar as
> it couldn’t correlate the response message to a request.    That is
> certainly the cause of the “leak” as the WS-Addressing stuff is not seeing
> a proper response to the request.
> >>
> >
> > Thanks Daniel for you reply
> >
> > In any case, if I don't use WS-Addressing , responses are correlated
> > to a request , even the JAX-WS proxy client is shared by many threads.
> > I don't know how Apache CXF do it but, would be possible to follow the
> > same correlation rule if RelatesTo header is not present in responses
> > ?
>
> Digging through the code, there certainly doesn’t look like an easy way.
> You’d likely need to write an interceptor that would grab the headers from
> the message, loop through, and if there isn’t a RelatesTo header, it either
> adds one or deletes all the addressing headers.
>
> > I would like to protect my webservice against malformed remote responses
>
> Well, there is the question of what SHOULD CXF be doing with this.   An
> argument certainly could be made that CXF should be throwing an exception
> at this point for a malformed Addressing message.   However, if that
> occurred, the response wouldn’t be processed at all and the client would
> get the exception.
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>
>

Re: WS-Addressing + CXF 2.7.8 memory leak

Posted by Daniel Kulp <dk...@apache.org>.
On Jan 13, 2014, at 2:52 PM, Jose María Zaragoza <de...@gmail.com> wrote:

> 2014/1/13 Daniel Kulp <dk...@apache.org>:
>> 
>> These are showing that the RelatesTo header wasn’t there or similar as it couldn’t correlate the response message to a request.    That is certainly the cause of the “leak” as the WS-Addressing stuff is not seeing a proper response to the request.
>> 
> 
> Thanks Daniel for you reply
> 
> In any case, if I don't use WS-Addressing , responses are correlated
> to a request , even the JAX-WS proxy client is shared by many threads.
> I don't know how Apache CXF do it but, would be possible to follow the
> same correlation rule if RelatesTo header is not present in responses
> ?

Digging through the code, there certainly doesn’t look like an easy way.   You’d likely need to write an interceptor that would grab the headers from the message, loop through, and if there isn’t a RelatesTo header, it either adds one or deletes all the addressing headers.  

> I would like to protect my webservice against malformed remote responses

Well, there is the question of what SHOULD CXF be doing with this.   An argument certainly could be made that CXF should be throwing an exception at this point for a malformed Addressing message.   However, if that occurred, the response wouldn’t be processed at all and the client would get the exception.   

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com



Re: WS-Addressing + CXF 2.7.8 memory leak

Posted by Jose María Zaragoza <de...@gmail.com>.
2014/1/13 Daniel Kulp <dk...@apache.org>:
>
> These are showing that the RelatesTo header wasn’t there or similar as it couldn’t correlate the response message to a request.    That is certainly the cause of the “leak” as the WS-Addressing stuff is not seeing a proper response to the request.
>


Thanks Daniel for you reply

In any case, if I don't use WS-Addressing , responses are correlated
to a request , even the JAX-WS proxy client is shared by many threads.
I don't know how Apache CXF do it but, would be possible to follow the
same correlation rule if RelatesTo header is not present in responses
?

I would like to protect my webservice against malformed remote responses

Regards

Re: WS-Addressing + CXF 2.7.8 memory leak

Posted by Daniel Kulp <dk...@apache.org>.
On Jan 13, 2014, at 7:13 AM, Jose María Zaragoza <de...@gmail.com> wrote:

> <?xml version="1.0" encoding="utf-8" standalone="yes"?>
> <SOAP-ENV:Envelope xmlns:add="http://schemas.xmlsoap.org/ws/2004/08/addressing"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Header>
> <add:MessageID>urn:uuid:8e51d90c-1013-48c6-bd74-b41751f3e0a7</add:MessageID>
> </SOAP-ENV:Header>
> <SOAP-ENV:Body>
> <ns:processResponse
> xmlns:ns="urn:com:external:types">
> <ns:resultCode>0</ns:resultCode>
> <ns:ldata>
> <ns:ldata2>
> <ns:data>
> <ns:id>1237</ns:id>
> </ns:data>
> </ns:ldata2>
> </ns:ldata>
> </ns:processResponse>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> 
> I  don't see any “RelatesTo” header in response. Should it ?

Yes.

Per the WS-Addressing Spec:
/wsa:RelatesTo
This OPTIONAL (repeating) element information item contributes one abstract [relationship] property value, in the form of a (URI, QName) pair. The [children] property of this element (which is of type xs:anyURI) conveys the [message id] of the related message. This element MUST be present if the message is a reply.

Note the last sentence.   For a reply message, the RelatesTo header must be there.


> 
> 2014-01-13 12:58:38.779 [http-8080-2] WARN  [ContextUtils] [doLog] -
> WS-Addressing - failed to retrieve Message Addressing Properties from
> context
> 2014-01-13 12:58:38.780 [http-8080-2] WARN  [ContextUtils] [doLog] -
> WS-Addressing - failed to retrieve Message Addressing Properties from
> context
> 2014-01-13 12:58:39.799 [http-8080-2] WARN  [ContextUtils] [doLog] -
> WS-Addressing - failed to retrieve Message Addressing Properties from
> context

These are showing that the RelatesTo header wasn’t there or similar as it couldn’t correlate the response message to a request.    That is certainly the cause of the “leak” as the WS-Addressing stuff is not seeing a proper response to the request.


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: WS-Addressing + CXF 2.7.8 memory leak

Posted by Jose María Zaragoza <de...@gmail.com>.
Thanks Daniel for your reply

My testing enviroment was

Java: version 1.6.0_24, vendor Sun Microsystems Inc.
-XX:MaxPermSize=128m
-Xmx1024m
-Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=true

Tomcat 6.0.23 + Apache CXF 2.7.8 + WS Addressing enabled


>Can you capture both the request and the response?
>Can you double check that the returns “RelatesTo” header has the appropriate msg id?

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Action xmlns="http://www.w3.org/2005/08/addressing">process</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:8e51d90c-1013-48c6-bd74-b41751f3e0a7
</MessageID>
<To xmlns="http://www.w3.org/2005/08/addressing">http://extermal.com/Process.jpd
</To>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
</soap:Header>
<soap:Body>
<process xmlns="urn:com:external:types">
<phone>3460003344</phone>
</process>
</soap:Body>
</soap:Envelope>


<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<SOAP-ENV:Envelope xmlns:add="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<add:MessageID>urn:uuid:8e51d90c-1013-48c6-bd74-b41751f3e0a7</add:MessageID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns:processResponse
xmlns:ns="urn:com:external:types">
<ns:resultCode>0</ns:resultCode>
<ns:ldata>
<ns:ldata2>
<ns:data>
<ns:id>1237</ns:id>
</ns:data>
</ns:ldata2>
</ns:ldata>
</ns:processResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I  don't see any “RelatesTo” header in response. Should it ?

> If you turn on logging, is there any warning about not being able to correlate the response?


2014-01-13 12:58:38.779 [http-8080-2] WARN  [ContextUtils] [doLog] -
WS-Addressing - failed to retrieve Message Addressing Properties from
context
2014-01-13 12:58:38.780 [http-8080-2] WARN  [ContextUtils] [doLog] -
WS-Addressing - failed to retrieve Message Addressing Properties from
context
2014-01-13 12:58:39.799 [http-8080-2] WARN  [ContextUtils] [doLog] -
WS-Addressing - failed to retrieve Message Addressing Properties from
context


>Can you use jvisualvm or similar to grab a heap dump and trace down to the appropriate place that is holding onto the strings?

Well  , I'm not an expert about JVM analyzing .
I did a heap dump when heap memory was in its higher value and I
executed "Find the 20 biggest objects *by retained size*" and I got

org.apache.cxf.endpoint.ClientImpl#1   50.703.981
org.apache.cxf.ws.addressing.soap.MAPCodec#1  50.691.121
java.util.concurrent.ConcurrentHashMap#108 50.691.026
java.util.concurrent.ConcurrentHashMap$Segment[]#108 50.690.986
....


If I look at references , I see :

- there are *a lot of * HashMap$Entry objects referencing to
ClientImpl object ( on its 'value' field )
Indeed, The percentage of HashMap$Entry instance's occurrences  is the
higher value in this heapdump


I tried to create a new JAX-WS proxy client per request and heap
memory behaviour is right.
( I was using a jaxws:client bean, a singleton , I guess )

So, looks like that jaxws proxy clients with WS-Addressing enabled
retain some info about request/response and , if the response doesn't
match what it is waiting, it doesn't clean that info  , is this right
?

So far, writing thread-safe code isn't enough : I must to
create/destroy a proxy client per request


Regards

Re: WS-Addressing + CXF 2.7.8 memory leak

Posted by Daniel Kulp <dk...@apache.org>.
We’ll likely need a more reproducible test case.    I just updated our ws-addressing system test to pretty much do:

        List<Long> mem = new ArrayList<Long>(12);
        for (int y = 0;  y < 10; y++) {
            for (int x = 0; x < 5000; x++) {
                greeter.greetMe("test");
            }
            System.gc(); System.gc(); 
            System.gc(); System.gc(); 
            System.gc(); System.gc(); 
            mem.add(Runtime.getRuntime().freeMemory());
        }
        int x = 0;
        for (Long l : mem) {
            System.out.println(x++ + ": " + l);
        }


and I’m not seeing any leaks:
0: 80937176
1: 80971944
2: 81026400
3: 81727120
4: 81712568
5: 81712544
6: 81712520
7: 81400968
8: 81712472
9: 81729112

I would assume with 50,000 messages that I’d see some significant decrease in the free memory or something.


Message sent:
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/“>
<soap:Header>
  <Action xmlns="http://www.w3.org/2005/08/addressing">http://apache.org/hello_world_soap_http/Greeter/greetMeRequest</Action>
  <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:64b8b662-2ff0-430c-98ea-45b57d6ce84a</MessageID>
  <To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:9002/SoapContext/SoapPort</To>
  <ReplyTo xmlns="http://www.w3.org/2005/08/addressing”>
    <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
  </ReplyTo>
  <customer:CustomerKey xmlns="http://www.w3.org/2005/08/addressing" xmlns:customer="http://example.org/customer" xmlns:wsa="http://www.w3.org/2005/08/addressing" wsa:IsReferenceParameter="1">Key#123456789</customer:CustomerKey>
</soap:Header>
<soap:Body>
   <greetMe xmlns="http://apache.org/hello_world_soap_http/types"><requestType>test</requestType></greetMe>
</soap:Body>
</soap:Envelope>

Message received:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/“>
<soap:Header>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://apache.org/hello_world_soap_http/Greeter/greetMeResponse</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:9fc9c1b9-687d-4377-8e0c-d4e19fb70533</MessageID>
<To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:64b8b662-2ff0-430c-98ea-45b57d6ce84a</RelatesTo>
</soap:Header>
<soap:Body>
<greetMeResponse xmlns="http://apache.org/hello_world_soap_http/types"><responseType>Hello test</responseType></greetMeResponse>
</soap:Body></soap:Envelope>


Can you capture both the request and the response?   If you turn on logging, is there any warning about not being able to correlate the response?   Can you use jvisualvm or similar to grab a heap dump and trace down to the appropriate place that is holding onto the strings?   Can you double check that the returns “RelatesTo” header has the appropriate msg id?

Dan



On Jan 10, 2014, at 6:20 AM, Jose María Zaragoza <de...@gmail.com> wrote:

> Hello:
> 
> I'm using CXF 2.7.8 and JAX-WS  to create a SOAP webservice
> 
> This webservice calls another webservice who requieres WS-Addressing
> 
> So, I declare a simple JAX-WS client with WS-Addressing enabled
> 
> 
> <jaxws:client id="client"
>                  serviceClass="com.external.WSPortType"
>                  address="http://extermal.com/Process.jpd"
>                  bindingId="http://schemas.xmlsoap.org/wsdl/soap/http">
> 
>         <jaxws:features>
>             <wsa:addressing xmlns:wsa="http://cxf.apache.org/ws/addressing"/>
>       </jaxws:features>
> </jaxws:client>
> 
> 
> I inject this bean into my webservice implementor with
> 
> @Autowired
> WSPortType client;
> 
> So, it's shared by all requests and I think is thread-safe 'in practice'
> (http://cxf.apache.org/faq.html#FAQ-AreJAX-WSclientproxiesthreadsafe?)
> 
> This client sends messages like
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Header>
> <Action xmlns="http://www.w3.org/2005/08/addressing">process</Action>
> <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:aebe3485-07bc-4af7-a3a5-c1df7af15adb
> </MessageID>
> <To xmlns="http://www.w3.org/2005/08/addressing">http://extermal.com/Process.jpd
> </To>
> <ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
> <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
> </ReplyTo>
> </soap:Header>
> <soap:Body>
> <process xmlns="urn:com:external:types">
> <phone>34606958413</phone>
> <filterParams>
> <field>data</field>
> </filterParams>
> </process>
> </soap:Body>
> </soap:Envelope>
> 
> and it receives the response correctly ( with the right MessageID )
> 
> 
> Well, this is the scenario.
> In this case, JVM memory heap increases all time and grows up until OOM
> Looking at jvisualm I see a lot of string objects being used by
> WS-addressing library
> If I comment WS-Addressing feature , all works fine and the memory
> heap's behaviour is normal.
> 
> What is wrong ? Any ideas ?
> If you need more data or other test, no problem
> 
> Thanks and regads

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com