Deadlock while history cleaning

We activated history cleaning, while our database rises too many GB of data. We set the following environment variables

            - FLOWABLE_ENABLE_HISTORY_CLEANING=true
            - FLOWABLE_HISTORY_CLEANING_AFTER=1d
            - FLOWABLE_HISTORY_CLEANING_CYCLE=0 13 7 * * ?
            - FLOWABLE_HISTORY_CLEANING_BATCH_SIZE=100

to activate the cleaning to a special time and watch if the database size decrease.

We found the job in the ACT_RU_TIMER_JOB table and at the special time it was removed and never come back.In the logs we see a deadlock and the database gives us the following output

------------------------
LATEST DETECTED DEADLOCK
------------------------
2026-01-16 09:00:55 139927588361792
*** (1) TRANSACTION:
TRANSACTION 97667773, ACTIVE 54 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 6 lock struct(s), heap size 1128, 2 row lock(s), undo log entries 3
MySQL thread id 131269938, OS thread handle 139926654817856, query id 1700653804 10.34.0.223 flowable update
INSERT INTO FLW_RU_BATCH(ID_, REV_, TYPE_, SEARCH_KEY_, SEARCH_KEY2_, CREATE_TIME_, COMPLETE_TIME_, STATUS_, BATCH_DOC_ID_, TENANT_ID_)
        VALUES ('663a3815-f2b1-11f0-b702-5a91dfd2a201',
                1,
                'historicProcessDelete',
                'Flowable BPMN History Cleanup',
                null,
                '2026-01-16 08:00:18.671',
                null,
                'inProgress',
                '663a3814-f2b1-11f0-b702-5a91dfd2a201',
                null)

*** (1) HOLDS THE LOCK(S):
RECORD LOCKS space id 9387 page no 194492 n bits 120 index PRIMARY of table `flowable`.`ACT_GE_BYTEARRAY` trx id 97667773 lock_mode X locks rec but not gap
Record lock, heap no 52 PHYSICAL RECORD: n_fields 8; compact format; info bits 0
 0: len 30; hex 36363361333831342d663262312d313166302d623730322d356139316466; asc 663a3814-f2b1-11f0-b702-5a91df; (total 36 bytes);
 1: len 6; hex 000005d24abd; asc     J ;;
 2: len 7; hex 81000000940110; asc        ;;
 3: len 4; hex 80000001; asc     ;;
 4: len 17; hex 6261746368446f63756d656e744a736f6e; asc batchDocumentJson;;
 5: SQL NULL;
 6: len 30; hex 7b226e756d6265724f66496e7374616e636573223a3638383236352c2262; asc {"numberOfInstances":688265,"b; (total 132 bytes);
 7: SQL NULL;


*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 9364 page no 4 n bits 72 index PRIMARY of table `flowable`.`FLW_RU_BATCH` trx id 97667773 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 3 PHYSICAL RECORD: n_fields 12; compact format; info bits 0
 0: len 30; hex 66373364326330622d663166382d313166302d613765612d646161336232; asc f73d2c0b-f1f8-11f0-a7ea-daa3b2; (total 36 bytes);
 1: len 6; hex 000005cdedfe; asc       ;;
 2: len 7; hex 81000000b1016a; asc       j;;
 3: len 4; hex 80000001; asc     ;;
 4: len 21; hex 686973746f72696350726f6365737344656c657465; asc historicProcessDelete;;
 5: len 29; hex 466c6f7761626c652042504d4e20486973746f727920436c65616e7570; asc Flowable BPMN History Cleanup;;
 6: SQL NULL;
 7: len 7; hex 99b8dea005028a; asc        ;;
 8: len 7; hex 99b8dea005028a; asc        ;;
 9: len 9; hex 636f6d706c65746564; asc completed;;
 10: len 30; hex 66373364326330612d663166382d313166302d613765612d646161336232; asc f73d2c0a-f1f8-11f0-a7ea-daa3b2; (total 36 bytes);
 11: SQL NULL;


*** (2) TRANSACTION:
TRANSACTION 97667685, ACTIVE 54 sec fetching rows
mysql tables in use 4, locked 4
LOCK WAIT 67041 lock struct(s), heap size 7053432, 2315887 row lock(s), undo log entries 3
MySQL thread id 131269936, OS thread handle 139926512092736, query id 1700652977 10.34.0.223 flowable executing
delete   BYTES_  
        from ACT_GE_BYTEARRAY BYTES_
        where BYTES_.ID_ in (
            select RES.BATCH_DOC_ID_
             
        from FLW_RU_BATCH RES
         WHERE  RES.TYPE_ = 'historicCaseDelete'
            
            
            
            
            
            
            
            
                and RES.COMPLETE_TIME_ < '2026-01-09 08:00:01.998' 
     
                and RES.BATCH_DOC_ID_ is not null
                 and RES.BATCH_DOC_ID_ != '' 

            union all

            select PARTS_.RESULT_DOC_ID_
            from FLW_RU_BATCH_PART PARTS_
            where PARTS_.RESULT_DOC_ID_ is not null
                 and PARTS_.RESULT_DOC_ID_ != '' 
                and PARTS_.BATCH_ID_ in (
                    select RES.ID_
                     
        from FLW_RU_BATCH RES
         WHERE  RES.TYPE_ = 'historicCaseDelete'
            
            
            
            
            
            
            
            
                and RES.COMPLETE_TIME_ < '2026-01-09 08:00:01.998' 
     
                )
        )

*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 9364 page no 4 n bits 72 index PRIMARY of table `flowable`.`FLW_RU_BATCH` trx id 97667685 lock mode S
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
 0: len 8; hex 73757072656d756d; asc supremum;;

Record lock, heap no 2 PHYSICAL RECORD: n_fields 12; compact format; info bits 0
 0: len 30; hex 32663662373261622d663261642d313166302d613637342d356564633336; asc 2f6b72ab-f2ad-11f0-a674-5edc36; (total 36 bytes);
 1: len 6; hex 000005d23184; asc     1 ;;
 2: len 7; hex 810000017f016a; asc       j;;
 3: len 4; hex 80000001; asc     ;;
 4: len 18; hex 686973746f7269634361736544656c657465; asc historicCaseDelete;;
 5: len 29; hex 466c6f7761626c6520434d4d4e20486973746f727920436c65616e7570; asc Flowable CMMN History Cleanup;;
 6: SQL NULL;
 7: len 7; hex 99b8e077881c98; asc    w   ;;
 8: len 7; hex 99b8e077881c98; asc    w   ;;
 9: len 9; hex 636f6d706c65746564; asc completed;;
 10: len 30; hex 32663662373261612d663261642d313166302d613637342d356564633336; asc 2f6b72aa-f2ad-11f0-a674-5edc36; (total 36 bytes);
 11: SQL NULL;

Record lock, heap no 3 PHYSICAL RECORD: n_fields 12; compact format; info bits 0
 0: len 30; hex 66373364326330622d663166382d313166302d613765612d646161336232; asc f73d2c0b-f1f8-11f0-a7ea-daa3b2; (total 36 bytes);
 1: len 6; hex 000005cdedfe; asc       ;;
 2: len 7; hex 81000000b1016a; asc       j;;
 3: len 4; hex 80000001; asc     ;;
 4: len 21; hex 686973746f72696350726f6365737344656c657465; asc historicProcessDelete;;
 5: len 29; hex 466c6f7761626c652042504d4e20486973746f727920436c65616e7570; asc Flowable BPMN History Cleanup;;
 6: SQL NULL;
 7: len 7; hex 99b8dea005028a; asc        ;;
 8: len 7; hex 99b8dea005028a; asc        ;;
 9: len 9; hex 636f6d706c65746564; asc completed;;
 10: len 30; hex 66373364326330612d663166382d313166302d613765612d646161336232; asc f73d2c0a-f1f8-11f0-a7ea-daa3b2; (total 36 bytes);
 11: SQL NULL;


*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 9387 page no 194492 n bits 120 index PRIMARY of table `flowable`.`ACT_GE_BYTEARRAY` trx id 97667685 lock_mode X waiting
Record lock, heap no 52 PHYSICAL RECORD: n_fields 8; compact format; info bits 0
 0: len 30; hex 36363361333831342d663262312d313166302d623730322d356139316466; asc 663a3814-f2b1-11f0-b702-5a91df; (total 36 bytes);
 1: len 6; hex 000005d24abd; asc     J ;;
 2: len 7; hex 81000000940110; asc        ;;
 3: len 4; hex 80000001; asc     ;;
 4: len 17; hex 6261746368446f63756d656e744a736f6e; asc batchDocumentJson;;
 5: SQL NULL;
 6: len 30; hex 7b226e756d6265724f66496e7374616e636573223a3638383236352c2262; asc {"numberOfInstances":688265,"b; (total 132 bytes);
 7: SQL NULL;

*** WE ROLL BACK TRANSACTION (1)

In a old thread, far years ago, i read, that flowable had problems with large amount of history entries to delete, so we increase the “CLEANING_AFTER” parameter. But also with a very old date, we get a deadlock. The latest entry in the ACT_HI_ACTINST table is from 2025-08-26 13:09:01.632

------------------------
LATEST DETECTED DEADLOCK
------------------------
2026-01-16 11:00:04 139927588361792
*** (1) TRANSACTION:
TRANSACTION 97693873, ACTIVE 0 sec fetching rows
mysql tables in use 4, locked 4
LOCK WAIT 7 lock struct(s), heap size 1128, 4 row lock(s), undo log entries 3
MySQL thread id 131294997, OS thread handle 139926516315712, query id 1701073838 10.34.0.223 flowable executing
delete   BYTES_  
        from ACT_GE_BYTEARRAY BYTES_
        where BYTES_.ID_ in (
            select RES.BATCH_DOC_ID_
             
        from FLW_RU_BATCH RES
         WHERE  RES.TYPE_ = 'historicCaseDelete'
            
            
            
            
            
            
            
            
                and RES.COMPLETE_TIME_ < '2025-03-22 10:00:04.231' 
     
                and RES.BATCH_DOC_ID_ is not null
                 and RES.BATCH_DOC_ID_ != '' 

            union all

            select PARTS_.RESULT_DOC_ID_
            from FLW_RU_BATCH_PART PARTS_
            where PARTS_.RESULT_DOC_ID_ is not null
                 and PARTS_.RESULT_DOC_ID_ != '' 
                and PARTS_.BATCH_ID_ in (
                    select RES.ID_
                     
        from FLW_RU_BATCH RES
         WHERE  RES.TYPE_ = 'historicCaseDelete'
            
            
            
            
            
            
            
            
                and RES.COMPLETE_TIME_ < '2025-03-22 10:00:04.231' 
     
                )
        )

*** (1) HOLDS THE LOCK(S):
RECORD LOCKS space id 9387 page no 34823 n bits 120 index PRIMARY of table `flowable`.`ACT_GE_BYTEARRAY` trx id 97693873 lock_mode X
Record lock, heap no 45 PHYSICAL RECORD: n_fields 8; compact format; info bits 0
 0: len 30; hex 30303030306234382d653237312d313166302d623061352d303234323061; asc 00000b48-e271-11f0-b0a5-02420a; (total 36 bytes);
 1: len 6; hex 0000057084c4; asc    p  ;;
 2: len 7; hex 82000000e902a5; asc        ;;
 3: len 4; hex 80000001; asc     ;;
 4: len 30; hex 686973742e7661722d657869745f67617465776179735f666f5f38363265; asc hist.var-exit_gateways_fo_862e; (total 62 bytes);
 5: SQL NULL;
 6: len 30; hex aced0005737200136a6176612e7574696c2e41727261794c6973747881d2; asc     sr  java.util.ArrayListx  ; (total 77 bytes);
 7: SQL NULL;


*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 9364 page no 4 n bits 80 index PRIMARY of table `flowable`.`FLW_RU_BATCH` trx id 97693873 lock mode S waiting
Record lock, heap no 8 PHYSICAL RECORD: n_fields 12; compact format; info bits 0
 0: len 30; hex 32313237613964392d663263322d313166302d386233632d306133396636; asc 2127a9d9-f2c2-11f0-8b3c-0a39f6; (total 36 bytes);
 1: len 6; hex 000005d2b0b2; asc       ;;
 2: len 7; hex 820000014c016a; asc     L j;;
 3: len 4; hex 80000001; asc     ;;
 4: len 21; hex 686973746f72696350726f6365737344656c657465; asc historicProcessDelete;;
 5: len 29; hex 466c6f7761626c652042504d4e20486973746f727920436c65616e7570; asc Flowable BPMN History Cleanup;;
 6: SQL NULL;
 7: len 7; hex 99b8e0a0040906; asc        ;;
 8: len 7; hex 99b8e0a0040906; asc        ;;
 9: len 9; hex 636f6d706c65746564; asc completed;;
 10: len 30; hex 32313237613964372d663263322d313166302d386233632d306133396636; asc 2127a9d7-f2c2-11f0-8b3c-0a39f6; (total 36 bytes);
 11: SQL NULL;


*** (2) TRANSACTION:
TRANSACTION 97693874, ACTIVE 0 sec starting index read
mysql tables in use 4, locked 4
LOCK WAIT 5 lock struct(s), heap size 1128, 2 row lock(s), undo log entries 3
MySQL thread id 131295002, OS thread handle 139925586851392, query id 1701073839 10.34.0.223 flowable executing
delete   BYTES_  
        from ACT_GE_BYTEARRAY BYTES_
        where BYTES_.ID_ in (
            select RES.BATCH_DOC_ID_
             
        from FLW_RU_BATCH RES
         WHERE  RES.TYPE_ = 'historicProcessDelete'
            
            
            
            
            
            
            
            
                and RES.COMPLETE_TIME_ < '2025-03-22 10:00:04.231' 
     
                and RES.BATCH_DOC_ID_ is not null
                 and RES.BATCH_DOC_ID_ != '' 

            union all

            select PARTS_.RESULT_DOC_ID_
            from FLW_RU_BATCH_PART PARTS_
            where PARTS_.RESULT_DOC_ID_ is not null
                 and PARTS_.RESULT_DOC_ID_ != '' 
                and PARTS_.BATCH_ID_ in (
                    select RES.ID_
                     
        from FLW_RU_BATCH RES
         WHERE  RES.TYPE_ = 'historicProcessDelete'
            
            
            
            
            
            
            
            
                and RES.COMPLETE_TIME_ < '2025-03-22 10:00:04.231' 
     
                )
        )

*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 9364 page no 4 n bits 80 index PRIMARY of table `flowable`.`FLW_RU_BATCH` trx id 97693874 lock_mode X locks rec but not gap
Record lock, heap no 8 PHYSICAL RECORD: n_fields 12; compact format; info bits 0
 0: len 30; hex 32313237613964392d663263322d313166302d386233632d306133396636; asc 2127a9d9-f2c2-11f0-8b3c-0a39f6; (total 36 bytes);
 1: len 6; hex 000005d2b0b2; asc       ;;
 2: len 7; hex 820000014c016a; asc     L j;;
 3: len 4; hex 80000001; asc     ;;
 4: len 21; hex 686973746f72696350726f6365737344656c657465; asc historicProcessDelete;;
 5: len 29; hex 466c6f7761626c652042504d4e20486973746f727920436c65616e7570; asc Flowable BPMN History Cleanup;;
 6: SQL NULL;
 7: len 7; hex 99b8e0a0040906; asc        ;;
 8: len 7; hex 99b8e0a0040906; asc        ;;
 9: len 9; hex 636f6d706c65746564; asc completed;;
 10: len 30; hex 32313237613964372d663263322d313166302d386233632d306133396636; asc 2127a9d7-f2c2-11f0-8b3c-0a39f6; (total 36 bytes);
 11: SQL NULL;


*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 9387 page no 34823 n bits 120 index PRIMARY of table `flowable`.`ACT_GE_BYTEARRAY` trx id 97693874 lock_mode X waiting
Record lock, heap no 45 PHYSICAL RECORD: n_fields 8; compact format; info bits 0
 0: len 30; hex 30303030306234382d653237312d313166302d623061352d303234323061; asc 00000b48-e271-11f0-b0a5-02420a; (total 36 bytes);
 1: len 6; hex 0000057084c4; asc    p  ;;
 2: len 7; hex 82000000e902a5; asc        ;;
 3: len 4; hex 80000001; asc     ;;
 4: len 30; hex 686973742e7661722d657869745f67617465776179735f666f5f38363265; asc hist.var-exit_gateways_fo_862e; (total 62 bytes);
 5: SQL NULL;
 6: len 30; hex aced0005737200136a6176612e7574696c2e41727261794c6973747881d2; asc     sr  java.util.ArrayListx  ; (total 77 bytes);
 7: SQL NULL;

*** WE ROLL BACK TRANSACTION (2)

The flowable logs says the following

2026-01-16 11:00:04.492	
	... 21 common frames omitted
2026-01-16 11:00:04.492		at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:75)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:48)
2026-01-16 11:00:04.492		at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
2026-01-16 11:00:04.492		at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
2026-01-16 11:00:04.492		at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:354)
2026-01-16 11:00:04.492		at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
2026-01-16 11:00:04.492		at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
2026-01-16 11:00:04.492		at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:124)
2026-01-16 11:00:04.492	Caused by: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
2026-01-16 11:00:04.492		at java.base/java.lang.Thread.run(Thread.java:1583)
2026-01-16 11:00:04.492		at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
2026-01-16 11:00:04.492		at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
2026-01-16 11:00:04.492		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.run(ExecuteAsyncRunnable.java:96)
2026-01-16 11:00:04.492		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.runInternally(ExecuteAsyncRunnable.java:122)
2026-01-16 11:00:04.492		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.executeJob(ExecuteAsyncRunnable.java:146)
2026-01-16 11:00:04.492		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.handleTransactionalJob(ExecuteAsyncRunnable.java:177)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
2026-01-16 11:00:04.492		at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57)
2026-01-16 11:00:04.492		at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
2026-01-16 11:00:04.492		at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:57)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:114)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.interceptor.CommandContext.close(CommandContext.java:76)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:218)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:378)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:649)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.db.DbSqlSession.flushBulkDeletes(DbSqlSession.java:673)
2026-01-16 11:00:04.492		at org.flowable.common.engine.impl.db.BulkDeleteOperation.execute(BulkDeleteOperation.java:34)
2026-01-16 11:00:04.492		at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:212)
2026-01-16 11:00:04.492		at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
2026-01-16 11:00:04.492		at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
2026-01-16 11:00:04.492	
### Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
2026-01-16 11:00:04.492	
### SQL: delete   BYTES_           from ACT_GE_BYTEARRAY BYTES_         where BYTES_.ID_ in (             select RES.BATCH_DOC_ID_                       from FLW_RU_BATCH RES          WHERE  RES.TYPE_ = ?                                                                                                                         and RES.COMPLETE_TIME_ < ?                        and RES.BATCH_DOC_ID_ is not null                  and RES.BATCH_DOC_ID_ != ''               union all              select PARTS_.RESULT_DOC_ID_             from FLW_RU_BATCH_PART PARTS_             where PARTS_.RESULT_DOC_ID_ is not null                  and PARTS_.RESULT_DOC_ID_ != ''                  and PARTS_.BATCH_ID_ in (                     select RES.ID_                               from FLW_RU_BATCH RES          WHERE  RES.TYPE_ = ?                                                                                                                         and RES.COMPLETE_TIME_ < ?                        )         )

2026-01-16 11:00:04.492	
### The error occurred while setting parameters
	
2026-01-16 11:00:04.492	
### The error may involve org.flowable.batch.service.impl.persistence.entity.BatchEntityImpl.bulkDeleteBytesForBatches-Inline
	
2026-01-16 11:00:04.492	
### The error may exist in org/flowable/batch/service/db/mapping/entity/Batch.xml
	
2026-01-16 11:00:04.492	
### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
	
2026-01-16 11:00:04.492	
org.apache.ibatis.exceptions.PersistenceException: 
	
2026-01-16 11:00:04.492	
2026-01-16T10:00:04.280Z ERROR 1 --- [flowable-rest] [        task-16] ltAsyncRunnableExecutionExceptionHandler : Job c1bb4281-f2c1-11f0-8b3c-0a39f6f48b4c failed
	
2026-01-16 11:00:04.492	
	... 21 common frames omitted
2026-01-16 11:00:04.492		at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:75)
2026-01-16 11:00:04.492		at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:48)
2026-01-16 11:00:04.492		at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
2026-01-16 11:00:04.492		at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
2026-01-16 11:00:04.492		at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:354)
2026-01-16 11:00:04.491		at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
2026-01-16 11:00:04.491		at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
2026-01-16 11:00:04.491		at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:124)
2026-01-16 11:00:04.491	Caused by: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
2026-01-16 11:00:04.491		at java.base/java.lang.Thread.run(Thread.java:1583)
2026-01-16 11:00:04.491		at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
2026-01-16 11:00:04.491		at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
2026-01-16 11:00:04.491		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.run(ExecuteAsyncRunnable.java:96)
2026-01-16 11:00:04.491		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.runInternally(ExecuteAsyncRunnable.java:122)
2026-01-16 11:00:04.491		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.executeJob(ExecuteAsyncRunnable.java:146)
2026-01-16 11:00:04.491		at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.handleTransactionalJob(ExecuteAsyncRunnable.java:177)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
2026-01-16 11:00:04.491		at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57)
2026-01-16 11:00:04.491		at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
2026-01-16 11:00:04.491		at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:57)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:114)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.interceptor.CommandContext.close(CommandContext.java:76)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:218)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:378)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:649)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.db.DbSqlSession.flushBulkDeletes(DbSqlSession.java:673)
2026-01-16 11:00:04.491		at org.flowable.common.engine.impl.db.BulkDeleteOperation.execute(BulkDeleteOperation.java:34)
2026-01-16 11:00:04.491		at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:212)
2026-01-16 11:00:04.491		at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
2026-01-16 11:00:04.491		at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
2026-01-16 11:00:04.491	### Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
		
2026-01-16 11:00:04.491	
### SQL: delete   BYTES_           from ACT_GE_BYTEARRAY BYTES_         where BYTES_.ID_ in (             select RES.BATCH_DOC_ID_                       from FLW_RU_BATCH RES          WHERE  RES.TYPE_ = ?                                                                                                                         and RES.COMPLETE_TIME_ < ?                        and RES.BATCH_DOC_ID_ is not null                  and RES.BATCH_DOC_ID_ != ''               union all              select PARTS_.RESULT_DOC_ID_             from FLW_RU_BATCH_PART PARTS_             where PARTS_.RESULT_DOC_ID_ is not null                  and PARTS_.RESULT_DOC_ID_ != ''                  and PARTS_.BATCH_ID_ in (                     select RES.ID_                               from FLW_RU_BATCH RES          WHERE  RES.TYPE_ = ?                                                                                                                         and RES.COMPLETE_TIME_ < ?                        )         )
	
2026-01-16 11:00:04.491	
### The error occurred while setting parameters
	
2026-01-16 11:00:04.491	
### The error may involve org.flowable.batch.service.impl.persistence.entity.BatchEntityImpl.bulkDeleteBytesForBatches-Inline
	
2026-01-16 11:00:04.491	
### The error may exist in org/flowable/batch/service/db/mapping/entity/Batch.xml
		
2026-01-16 11:00:04.491	
### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction

We are runnning the latest docker container flowable-rest from Aug 21, 2025 at 1:49 pm

Why has flowable such problems on history cleaning?

@filiphr Can you help me with this topic? Is this a known problem in your application? Is see some similar issues like Deadlock found when trying to get lock; try restarting transaction #3866 · Issue #4016 · flowable/flowable-engine · GitHub but they are also not answered from anyone.

What database are you using? And secondly, what hardware - most often deadlock exception point at not having enough resources for the db.

Some databases will quickly throw a deadlock exception when under load - if too many rowlocks are taken on the same row, a deadlock is thrown (which is very different from the pure definition of a deadlock).

@joram We are using a MySQL 8.0 for flowable on a Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz with 4 GB of RAM. The RAM is with 82.75% used not really full and never goes in critical zones. The server is only a database server, so no other operations are going on there.

Also we are using this database for a long time and only flowable has on its houskeeping job this problems. The normal flowable jobs are running well. Also our other applications never had problems on this database.

Hey @MeAndMyTeam ,

what is your configured innodb_buffer_pool_size?

Greetings Christopher

@WelschChristopher The innodb_buffer_pool_size is 1879048192

Hey @MeAndMyTeam

What numbers are we talking about? 5 GB? 100GB? what is many?

@WelschChristopher In the highest point it was 8 GB of data on the whole flowable database.
in the meantime we delete the data over the /history/historic-process-instances/{process_id} endpoint on our own, but also with small data of 300MB the deadlock occurs again.