Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-331

JPA afterCompletion sync may be called from non-application thread, resolve concurrency concern

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Done
    • Major
    • 8.0.0.Alpha1
    • None
    • JPA / Hibernate
    • None

    Description

      For transaction scoped entity managers, the closing the of entity manager is deferred until after the transaction completes.

      It is possible that the transaction manager/service may call the Transaction sync from a non-application thread (tx timeout reaper thread or normal completion in remote propagated tx case). Guards need to be added to make sure that a tx timeout, doesn't interfere with normal application usage of the entity manager.

      I think that there are two main cases to be concerned with that involve the afterCompletion sync being invoked in a non-application thread:

      1. TX reaper or other background thread calls afterCompletion while application thread is in (transaction scope) entityManager invocation.
      2. TX reaper or other background thread calls afterCompletion while application thread is not in (transaction scope) entityManager invocation.

      Extended persistence contexts do not get closed when the JTA transaction that they are joined to are closed (in case anyone is curious).

      If we are in #1 above, could we delegate the closing of the EntityManager to the in progress EntityManager invocation (to avoid closing the thread unsafe invocation)? Or prevent the background thread from closing the EntityManager until the current EntityManager invocation completes. Or push the requirement up to the top-level EE container (e.g. managed bean, EJB3, web, ...).

      The related classes are org.jboss.as.jpa.container.TransactionScopedEntityManager (or AbstractEntityManager) + org.jboss.as.jpa.transaction.TransactionUtil classes.

      Attachments

        Issue Links

          Activity

            People

              pgier@redhat.com Paul Gier (Inactive)
              smarlow1@redhat.com Scott Marlow
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: