Uploaded image for project: 'IronJacamar'
  1. IronJacamar
  2. JBJCA-1495

CachedConnectionManager meta-aware object stack does not work correctly with transactional invocations

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • None
    • None

      In some scenarios CCM may produce "IJ000152: Trying to return an unknown connection". One of this scenario, described initially in WFLY-19082, is as follows:

      //1
      a.a(); // from some other component f.e. servlet
      
      
      @Stateless
      class A {
          
          @Resource
          private javax.sql.DataSource dataSource;
          
          @EJB
          private B b;
      
         @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
         void a(){
             //2
             Connection con = dataSource.getConnection();
             //3
             b.b();
             //5
         }
      }
      
      @Stateless
      class B {
      
          @PersistenceContext(...)
          EntityManager em;
      
         @TransactionAttribute(TransactionAttributeType.REQUIRED)
         void b(){
             //4
             em.find(...);
         }
      }
      
      

      Failure scenario:
      1. Some other component invoked A#a method. Transaction is not started but meta-aware object (MET1) is put on CCM stack.
      2. As the connection (con) is allocated, it is registered within CCM and associated with MET1.
      3. Because invocation of component B another meta-aware object (MET2) is put on the CCM start. This time transaction (t) is started.
      4. Because entity manager lookup, another connection (b_con) is started and registered within CCM, but this one is associated with MET2.
      5. Transactional invocation of B#b finishes. MET2 is removed from the stack and MET1 is currently on top). It is important to note that this happens before transaction t commit process starts. After the commit later proceeds Hibernate is closing the connections associated with the transaction. In our example Hibernate closes b_con, which results in unregistering this connection from CCM. The problem is that b_con was associated with MET2 and not MET1 which is currently at the top of the stack hence the error.

      Looking at the above scenario it may seems that much simple reproducer (one transactional component invocation) would be enough to present this error. This is not the case for the following reasons:

      • if there is no outer invocation (A#a) then and only B#b then after B#b is finished there would be nothing on a CCM stack. In such case CCM just returns without any error
      • if there is no connection allocated in outer connection, MET1 would contain no records, which again makes CCM to immediately return without any errors

              tadamski@redhat.com Tomasz Adamski
              tadamski@redhat.com Tomasz Adamski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: