0 Replies Latest reply on Dec 26, 2011 10:03 AM by rehdiehome

    ExceptionFilter does NOT rollback active transactions (+ solution to fix this)

    rehdiehome

      Hi all,


      since this problem took quite a long time to reproduce and fix, I'll share it here and hope, this might help some of you.


      We are using SEAM-Version:  2.2.2 deployed in a tomcat 7 (using EntityTransactions).



      We had the problem, that exceptions in the APPLY REQUEST VALUES phase did produce dangling transactions, which were never rolled back. The reason was, that the ExceptionFilter invoked  rollbackTransactionIfNecessary() after Lifcecycle.endRequest (which destroys the event-context, where the current UserTransactions is stored!:


         protected void endWebRequestAfterException(HttpServletRequest request, HttpServletResponse response, Exception e)
            throws ServletException, IOException
         {
      
            log.debug("running exception handlers");
            ....
         
            // Ensure that the call in which the exception occurred was cleaned up - it might not be, and there is no harm in
            // trying
            Lifecycle.endRequest();
            ....
      
            // Now do the exception handling
            try
            {
               // roll back moved up! (must occur prior to Lifecycle.endRequest())!
               rollbackTransactionIfNecessary();
               Exceptions.instance().handle(e);
            }
            catch(ServletException se)
            {
               throw se;
            }
            ......
            
      
         }
      
      



      I moved the call to rollbackTransactionIfNecessary() to the line before Lifecycle.endRequest() and everything works correct now:


         protected void endWebRequestAfterException(HttpServletRequest request, HttpServletResponse response, Exception e)
            throws ServletException, IOException
         {
      
            log.debug("running exception handlers");
            ....
      
            rollbackTransactionIfNecessary();
         
            // Ensure that the call in which the exception occurred was cleaned up - it might not be, and there is no harm in
            // trying
            Lifecycle.endRequest();
            ....
      
            // Now do the exception handling
            try
            {
               // roll back moved up! (must occur prior to Lifecycle.endRequest())!
               Exceptions.instance().handle(e);
            }
            catch(ServletException se)
            {
               throw se;
            }
            ......
            
      
         }
      
      



      regards and a happy new year :-)


      Dieter