flowable / flowable-engine

A compact and highly efficient workflow and Business Process Management (BPM) platform for developers, system admins and business users.
https://www.flowable.org
Apache License 2.0
7.83k stars 2.59k forks source link

Got CannotCreateTransactionException when restarting with Spring DevTools #2823

Open suzaku opened 3 years ago

suzaku commented 3 years ago

Describe the bug

I've set up Spring to restart automatically when changes are detected in the processes directory:

devtools.restart:
    additional-paths: /myproject/src/main/resources/processes
    enabled: true

When I add new bpmn files or remove existing bpmn files in the processes directory, the change is detected by devtools and it tries to restart the service. But a CannotCreateTransactionException is raised every time from 2021-02-19 03:13:31.747 ERROR 287 --- [ange-detector-1] i.m.EventRegistryChangeDetectionRunnable : Exception while detecting event registry changes:

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: HikariDataSource HikariDataSource (flowable) has been closed.

Lin-Liang commented 3 years ago

Hey guys, I also meet this issue. Very hopefully it can be solved soon :pray: That is my configuration.

<!-- https://mvnrepository.com/artifact/org.flowable/flowable-engine -->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>6.5.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>2.7.9</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.16</version>
        </dependency>
spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:postgresql://localhost:5432/flowable_test
    hikari:
      poolName: flowable_test
      maxLifetime: 600000
      idleTimeout: 300000
      minimumIdle: 10
      maximumPoolSize: 50
      connection-test-query: select 1
      connection-timeout: 3000
    username: postgres
    password: postgres

The usage scenario is that we use spring dev tools to automatically restart our project when our code changes. The problem will reappear when the application is restarted. If you are using the Intellij idea, you need to manually compile the code to trigger the restart。 The error log is the same as above.

The code that throws the error is org.flowable.eventregistry.impl.management.EventRegistryChangeDetectionRunnable#run. This is a timed task that runs every 60 seconds.

After spring dev tools restarted the project, spring passed a new data source to flowable, and this data source is valid. see code org.flowable.spring.SpringProcessEngineConfiguration#setDataSource. But EventRegistryChangeDetectionRunnable is still using the old data source which has been shut down. image

ptlive1001 commented 3 years ago

Has the problem been solved?

suzaku commented 3 years ago

@ptlive1001 It seems like nobody from the flowable team is looking at the issues. I managed to solve this problem by using FileSystemWatcher from spring devtools.

ptlive1001 commented 3 years ago

Looking forward to official solutions