11 Replies Latest reply on Feb 2, 2007 1:07 PM by timfox

    Memory Leak with EJB3 ?

    mwelss

      Hi,

      we are using jboss 404 with messaging 1.0.1.GA and EJB3
      The queue in question is non persistent and does not grow,
      so the messages do get delivered and processed fast enough.

      We observe the heap growing with instances of TxState and ArrayLists which belong to TxState, see output of heap analyzer below. At that point in time there are 338134 instances of TxState.

      References by Type

      class org.jboss.jms.tx.TxState [0x5aa9a200]

      Referrers by Type
      Class / Count
      EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap$Entry / 337800
      org.jboss.jms.tx.TransactionRequest / 215

      Referees by Type
      Class / Count
      java.util.ArrayList / 676268


      best regards,

      Martin

        • 1. Re: Memory Leak with EJB3 ?
          timfox

          Transactions only get stored in the map on the server when your transaction manager is doing 2PC and they have been successfully prepared.

          On commit or rollback they should be removed from the map.

          The fact they are not being removed implies to me that you're transaction manager is not calling commit or rollback for some reason.

          Can you enable trace logging on the server and look in the logs for the following strings? :

          
          created transaction
          
          commit process complete
          
          rollback process complete
          
          


          If you're not expecting rollbacks then you should see the same or similar number of "created transaction" and "commit process complete".

          Can you try this out?

          Thanks.





          • 2. Re: Memory Leak with EJB3 ?
            mwelss

            We see the same number of creates and commits.

            It is a EJB3 MDB which sends new messages and accesses the database in the onMessage() method.

            • 3. Re: Memory Leak with EJB3 ?
              timfox

              That's strange.

              The only place in the code that a tx is added to the map is in the create, and it's only removed in two places - commit or rollback.

              Can you replicate this is in a test case and send to me? thanks.

              • 4. Re: Memory Leak with EJB3 ?
                timfox
                • 5. Re: Memory Leak with EJB3 ?
                  dunks80

                  JBoss 4.0.5.GA
                  JBoss Messaging 1.0.1
                  Jboss TS 4.2.2
                  MS-SQL 2000 w/jtds driver

                  I'm seeing the same problem. Tenured gen is filling up with org.jboss.jms.tx.TxState and org.jboss.jms.tx.LocalTx when processing messages using an EJB3 MDB. I am debugging through the org.jboss.jms.tx.MessagingXAResource and here is what I'm seeing...

                  In

                  public void start(Xid xid, int flags) throws XAException
                  A new TxState is put into the ResourceManager's map of transactions.

                  In
                  public void end(Xid xid, int flags) throws XAException
                  Another new TxState is put into the map of transactions b/c of the call to unsetCurrentTransactionId.
                   // Don't unset the xid if it has previously been suspended. The session could have been
                   // recycled
                   if (xid.equals(sessionState.getCurrentTxId()))
                   {
                   sessionState.setCurrentTxId(rm.createLocalTx());
                   }
                  

                  which is called no matter what the outcome of the transaction based on this code...
                  public void end(Xid xid, int flags) throws XAException
                   {
                   if (trace) { log.trace(this + " ending " + xid + ", flags: " + flags); }
                  
                   synchronized (this)
                   {
                   switch (flags)
                   {
                   case TMSUSPEND :
                   unsetCurrentTransactionId(xid);
                   rm.suspendTx(xid);
                   break;
                   case TMFAIL :
                   unsetCurrentTransactionId(xid);
                   rm.endTx(xid, false);
                   break;
                   case TMSUCCESS :
                   unsetCurrentTransactionId(xid);
                   rm.endTx(xid, true);
                   break;
                   }
                   }
                   }
                  

                  I'm not by any means an expert in the TX code...but this unsetCurrentTransactionId seems to be what's causing the problem...the xid is always equal to the currentTxId so a new TxState is added to the ResourceManager's map of transactions. Is this correct? Why? This results in two TxState objects being put into the transaction map for each transaction...and only one gets removed when commit is called...causing the heap to grow.


                  In
                  public void commit(Xid xid, boolean onePhase) throws XAException
                  the first TxState is removed from the map of transactions.

                  Is there something I've done wrong to cause this behavior? TransactionAttribute settings? Some setting in JBoss Messaging? Of is this a genuine bug?


                  • 6. Re: Memory Leak with EJB3 ?
                    timfox

                    Looks like it could be a bug.

                    We're massively rushed off our feet right now, but could you add a bug report in JIRA, and I'll take a deeper look at it ASAP?

                    Thanks.

                    • 7. Re: Memory Leak with EJB3 ?
                      dunks80

                      Are you sure I should create a new issues? This doesn't fall under http://jira.jboss.com/jira/browse/JBMESSAGING-638? If not I'll be happy to create a new one.

                      • 8. Re: Memory Leak with EJB3 ?
                        timfox

                        Sorry, you're quite right.

                        Could you add a comment to the existing issue on you're explanation for the leak, and link to this thread?

                        Thanks :)

                        • 9. Re: Memory Leak with EJB3 ?
                          timfox

                          I have replicated this problem in a couple of test cases.

                          The fix should be pretty straightforward.

                          We are putting out a service pack for 1.0.1 (SP4) probably some time next week. I will make sure it gets into that.

                          • 10. Re: Memory Leak with EJB3 ?
                            timfox
                            • 11. Re: Memory Leak with EJB3 ?
                              timfox

                              And will soon be in SP4