You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "thiagoelg (via GitHub)" <gi...@apache.org> on 2026/09/11 19:27:25 UTC

[I] Dev mode: "EntityManagerFactory is closed" after a few live reloads when kogito-addons-quarkus-data-index-jpa is used [incubator-kie]

thiagoelg opened a new issue, #7106:
URL: https://github.com/apache/incubator-kie/issues/7106

   ## Describe the bug
   
   When `kogito-addons-quarkus-data-index-jpa` is on the classpath, a Quarkus dev mode application stops working after a few live reloads. It fails to start with `java.lang.IllegalStateException: EntityManagerFactory is closed` and never recovers.
   
   **What goes wrong:**
   
   `KogitoBeanProducer` produces the CDI `UnitOfWorkManager` bean by returning a JVM-wide static singleton, `StaticUnitOfWorkManger.staticUnitOfWorkManager()`. Quarkus dev mode throws the application away on each reload, but it does not throw that static object away, because the class holding it comes from a dependency JAR that the base runtime ClassLoader keeps loaded.
   
   So the same `UnitOfWorkManager`, and the same `EventManager` inside it, is reused by every reload. Each restart adds its `EventPublisher`s to it, and `addPublisher` only ever adds — there is no matching remove. After a few reloads, publishing an event calls publishers that belong to applications which already shut down. Those old publishers still point at an `EntityManagerFactory` that was closed when their application stopped, which is the error above.
   
   The data index add-on is not the bug. It is just the only publisher that opens a Hibernate session straight away, so it is the first one to fail visibly.
   
   Reproducer, with public dependencies only and full details: https://github.com/thiagoelg/quarkus-dev-mode-emf-closed-repro
   
   ## Expected behavior
   
   Each dev mode live reload starts a clean application. Event publishers from earlier reloads are discarded with the application they belong to.
   
   ## Actual behavior
   
   The first start and the first reload work. From the second reload the application fails to start, requests return HTTP 500, and it never recovers.
   
   ```
   Caused by: java.lang.IllegalStateException: EntityManagerFactory is closed
   	at org.hibernate.internal.SessionFactoryImpl.validateNotClosed(SessionFactoryImpl.java:587)
   	at io.quarkus.hibernate.orm.runtime.session.TransactionScopedSession.find(TransactionScopedSession.java:199)
   	at org.kie.kogito.index.jpa.storage.AbstractJPAStorageFetcher.get(AbstractJPAStorageFetcher.java:91)
   	at org.kie.kogito.index.service.IndexingService.indexProcessDefinition(IndexingService.java:98)
   	at org.kie.kogito.index.addon.event.DataIndexEventPublisher.publish(DataIndexEventPublisher.java:60)
   	at org.kie.kogito.event.impl.BaseEventManager.publish(BaseEventManager.java:58)
   	at org.kie.kogito.services.registry.ProcessDefinitionEventRegistry.register(ProcessDefinitionEventRegistry.java:77)
   	at org.kie.kogito.quarkus.registry.ProcessDefinitionRegistration.onStartUp(ProcessDefinitionRegistration.java:53)
   ```
   
   Full stack trace and logs: https://github.com/thiagoelg/quarkus-dev-mode-emf-closed-repro
   
   ## How to Reproduce?
   
   https://github.com/thiagoelg/quarkus-dev-mode-emf-closed-repro has the project and a `reproduce.sh` script that does all of this automatically.
   
   1. Build `apache/incubator-kie` 999-SNAPSHOT locally.
   2. Run `mvn quarkus:dev` in the reproducer and POST to `/LoadTest` → 201.
   3. Edit the BPMN file to trigger a live reload, then POST again → 201.
   4. Edit it again, then POST again → 500, `EntityManagerFactory is closed`.
   
   ## Output of `uname -a` or `ver`
   
   ```
   Darwin <redacted> 25.5.0 Darwin Kernel Version 25.5.0: Mon Apr 27 20:41:15 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6041 arm64 arm Darwin
   ```
   
   ## Output of `java -version`
   
   ```
   openjdk version "17.0.9" 2023-10-17
   OpenJDK Runtime Environment Temurin-17.0.9+9 (build 17.0.9+9)
   OpenJDK 64-Bit Server VM Temurin-17.0.9+9 (build 17.0.9+9, mixed mode)
   ```
   
   ## GraalVM version (if different from Java)
   
   n/a (JVM mode)
   
   ## Kogito version or git rev (or at least Quarkus version if you are using Kogito via Quarkus platform BOM)
   
   `apache/incubator-kie` `999-SNAPSHOT` (main), Quarkus 3.33.3.2
   
   ## Build tool (ie. output of `mvnw --version` or `gradlew --version`)
   
   ```
   Apache Maven 3.9.16 (2bdd9fddda4b155ebf8000e807eb73fd829a51d5)
   ```
   
   ## Additional information
   
   A probe logged object identities at each dev mode start. `Application` is a new object every time, as it should be. The `UnitOfWorkManager` and its `EventManager` are the same objects every time, and the publisher count grows by one per reload:
   
   | Start | Application | UnitOfWorkManager | EventManager | Publishers |
   |---|---|---|---|---|
   | restart no:0 | `@2b15af5c` | `DefaultUnitOfWorkManager@135ba` | `@78f53ca9` | 1 |
   | restart no:1 | `@41d76578` | `DefaultUnitOfWorkManager@135ba` | `@78f53ca9` | 2 |
   | restart no:2 | `@266a08bf` | `DefaultUnitOfWorkManager@135ba` | `@78f53ca9` | 3 |
   | restart no:3 | `@6637bbb9` | `DefaultUnitOfWorkManager@135ba` | `@78f53ca9` | 4 |
   | restart no:4 | `@72a2ae1f` | `DefaultUnitOfWorkManager@135ba` | `@78f53ca9` | 5 |
   
   `AbstractProcessConfig` leaks `UnitOfWorkEventListener`s the same way, because `DefaultUnitOfWorkManager.register` is also add-only.
   
   Removing `kogito-addons-quarkus-data-index-jpa` makes the reloads clean. A plain Quarkus application with the same shape does not reproduce it — there is no static event manager in Quarkus itself.
   
   Which reload fails first depends on when an old publisher first hits a closed factory. The growth is steady, so a failure is unavoidable; here it is consistently the second reload.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [I] Dev mode: "EntityManagerFactory is closed" after a few live reloads when kogito-addons-quarkus-data-index-jpa is used [incubator-kie]

Posted by "thiagoelg (via GitHub)" <gi...@apache.org>.
thiagoelg commented on issue #7106:
URL: https://github.com/apache/incubator-kie/issues/7106#issuecomment-5698881794

   Fixed in https://github.com/apache/incubator-kie/pull/7107


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [I] Dev mode: "EntityManagerFactory is closed" after a few live reloads when kogito-addons-quarkus-data-index-jpa is used [incubator-kie]

Posted by "thiagoelg (via GitHub)" <gi...@apache.org>.
thiagoelg closed issue #7106: Dev mode: "EntityManagerFactory is closed" after a few live reloads when kogito-addons-quarkus-data-index-jpa is used
URL: https://github.com/apache/incubator-kie/issues/7106


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org