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

EntityManager leak in rare case

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 27.0.1.Final
    • JPA / Hibernate
    • None
    • ---
    • ---

    Description

      WildFly leaks EntityManager instances (i.e. it does not close them) in the case where a container-managed EM is invoked by a non-EJB bean, outside of a transaction, on a non-Servlet thread. In my case, I'm invoking a read-only stored procedure, from an ApplicationScoped CDI bean, on a thread created by ManagedThreadFactory.

      The cause is in TransactionScopedEntityManager and NonTxEmCloser. In this scenario, nothing calls NonTxEmCloser#pushCall() or popCall(). So TransactionScopedEntityManager creates a new EM, but the EM is not stored anywhere and is never closed.

      The fact that the EM is never closed can lead to resource leaks. I discovered this problem because my database connection pool was getting exhausted. I'm using EclipseLink instead of Hibernate, and EclipseLink's implementation of StoredProcedureQuery doesn't release the connection until the EM is closed or the query is GC'd.

      I managed to hackfix this in my application by adding calls to pushCall() and popCall(), but this should be fixed properly somehow. Possibly by having TransactionScopedEntityManager check if NonTxEmCloser actually stored the EM, and if not, closing the EM after the current statement completes.

      Attachments

        Activity

          People

            smarlow1@redhat.com Scott Marlow
            rdicroce Richard DiCroce (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: