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

Memory leak in Hibernate pending-puts cache when L2 cache is enabled

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Duplicate
    • Optional
    • None
    • 18.0.1.Final, 19.0.0.Final
    • JPA / Hibernate
    • None

    Description

      Under certain conditions, described below, WildFly / Hibernate can leak memory into the pending-puts cache eventually causing an OutOfMemoryError. Attached you can find a web application and a standalone client that can be used to reproduce the problem. The web app defines two entities: a Parent and a Child. There is a bidirectional one-to-many relationship between the Parent and the Child. JPA L2 cache is enabled (Infinispan is the cache provider).

      Repeatedly executing a transaction that creates a new Child and adds it to the list of children in the Parent will cause the memory usage to increase steadily until OOM is encountered. If the execution of these transactions is stopped before reaching OOM, the memory will be reclaimed after a few minutes of inactivity.

      Attached you can find the following:

      • simple-hibernate-war.war - the web app that can be deployed in WildFly to reproduce the issue.
      • simple-hibernate-war.zip - the source code for the above web app. The servlet that is invoked by the client to create and persist a new Child is com.microfocus.sa.web.AddChildServlet
      • simple-hibernate-war-client.zip - the standalone client that can be used to invoke the AddChildServlet. After unzipping the archive, the client can be run with the following command from the client folder:

      java -cp bin com.microfocus.sa.client.AddChildClient

      If you need to run the client multiple times, you have to restart WildFly in between the runs, to start from a fresh state (the web app uses the h2 in memory databasewhich is reset at each restart).

      • pending-puts-leak.PNG - a screeshot from Memory Analyzer showing a leaked SessionImpl instance

      Attachments

        1. simple-hibernate-war.war
          16 kB
        2. simple-hibernate-war.zip
          14 kB
        3. simple-hibernate-war-client.zip
          5 kB
        4. pending-puts-leak.PNG
          pending-puts-leak.PNG
          120 kB
        5. PathToGCRoots_strong_refs.PNG
          PathToGCRoots_strong_refs.PNG
          67 kB
        6. beforeOOM.hprof.zip
          22.21 MB
        7. afterOOM.hprof.zip
          22.22 MB
        8. simple-hibernate-war.war.2020-03-25
          17 kB
        9. simple-hibernate-war.zip.2020-03-25
          29 kB
        10. simple-hibernate-war-client.zip.2020-03-25
          5 kB

        Issue Links

          Activity

            People

              smarlow1@redhat.com Scott Marlow
              spotra Sorin Potra (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: