The countersigned node execute returned or withdrawn,There is a probability that an error will be reported

When I execute an approval flow that contains countersigned nodes, when I execute to the countersigned node, I perform a return or cancel operation on the countersigned node, there is a probability that an error will be reported.

The following is the error log

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`easycode`.`act_ru_task`, CONSTRAINT `ACT_FK_TASK_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `act_ru_execution` (`ID_`))
### The error may exist in org/flowable/db/mapping/entity/Execution.xml
### The error may involve org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.deleteExecution-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
### Cause: java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`easycode`.`act_ru_task`, CONSTRAINT `ACT_FK_TASK_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `act_ru_execution` (`ID_`))
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:196)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:209)
	at org.flowable.common.engine.impl.db.DbSqlSession.flushDeleteEntities(DbSqlSession.java:641)
	at org.flowable.common.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:598)
	at org.flowable.common.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:365)
	at org.flowable.common.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:212)
	at org.flowable.common.engine.impl.interceptor.CommandContext.close(CommandContext.java:70)
	at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:114)
	at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:57)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
	at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57)
	at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
	at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
	at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
	at org.flowable.engine.impl.RuntimeServiceImpl.changeActivityState(RuntimeServiceImpl.java:765)
	at org.flowable.engine.impl.runtime.ChangeActivityStateBuilderImpl.changeState(ChangeActivityStateBuilderImpl.java:225)

This is my bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
  <process id="proc-fapiay-a3poznfhv" name="测试会签问题" processType="None" isClosed="false" isExecutable="true">
    <startEvent id="startEvent1" flowable:formFieldValidation="true" />
    <userTask id="sid-05344D6B-1C79-4203-971E-00F9FDDBD716" name="发起流程" flowable:assignee="${initiator}" flowable:formFieldValidation="true" flowable:buttons="{&#39;agree&#39;:{&#39;display&#39;:true,&#39;name&#39;:&#39;通过&#39;,&#39;sort&#39;:1},&#39;sendback&#39;:{&#39;display&#39;:true,&#39;name&#39;:&#39;退回&#39;,&#39;sort&#39;:2}}" flowable:form-field="{&#39;undefined&#39;:{&#39;hide&#39;:false,&#39;edit&#39;:true},&#39;name&#39;:{&#39;hide&#39;:false,&#39;edit&#39;:true},&#39;remarks&#39;:{&#39;hide&#39;:false,&#39;edit&#39;:true}}">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler">false</modeler:initiator-can-complete>
      </extensionElements>
      <outgoing>Flow_0jhlrng</outgoing>
    </userTask>
    <sequenceFlow id="sid-604CE78D-58FC-495B-A3F4-F3634C685BBC" sourceRef="startEvent1" targetRef="sid-05344D6B-1C79-4203-971E-00F9FDDBD716" />
    <userTask id="Activity_007xaw4" name="测试2" flowable:assignee="${assignee}" flowable:candidateUsers="" flowable:buttons="{&#39;agree&#39;:{&#39;display&#39;:true,&#39;name&#39;:&#39;通过&#39;,&#39;sort&#39;:1},&#39;sendback&#39;:{&#39;display&#39;:true,&#39;name&#39;:&#39;退回&#39;,&#39;sort&#39;:2}}" flowable:form-field="{&#39;undefined&#39;:{&#39;hide&#39;:false,&#39;edit&#39;:true},&#39;name&#39;:{&#39;hide&#39;:false,&#39;edit&#39;:true},&#39;remarks&#39;:{&#39;hide&#39;:false,&#39;edit&#39;:true}}">
      <incoming>Flow_0jhlrng</incoming>
      <outgoing>Flow_0m254lp</outgoing>
      <multiInstanceLoopCharacteristics flowable:elementVariable="assignee" flowable:collection="${hrService.getLoginUserId()}">
        <completionCondition xsi:type="tFormalExpression">${nrOfCompletedInstances/nrOfInstances == 1 }</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>
    <sequenceFlow id="Flow_0m254lp" sourceRef="Activity_007xaw4" targetRef="Event_132c7vv" />
    <endEvent id="Event_132c7vv">
      <incoming>Flow_0m254lp</incoming>
    </endEvent>
    <sequenceFlow id="Flow_0jhlrng" sourceRef="sid-05344D6B-1C79-4203-971E-00F9FDDBD716" targetRef="Activity_007xaw4" />
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_proc-fapiay-a3poznfhv">
    <bpmndi:BPMNPlane id="BPMNPlane_proc-fapiay-a3poznfhv" bpmnElement="proc-fapiay-a3poznfhv">
      <bpmndi:BPMNShape id="BPMNShape_startEvent1" bpmnElement="startEvent1">
        <omgdc:Bounds x="100" y="163" width="30" height="30" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_sid-05344D6B-1C79-4203-971E-00F9FDDBD716" bpmnElement="sid-05344D6B-1C79-4203-971E-00F9FDDBD716">
        <omgdc:Bounds x="220" y="138" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_007xaw4_di" bpmnElement="Activity_007xaw4">
        <omgdc:Bounds x="470" y="138" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_132c7vv_di" bpmnElement="Event_132c7vv">
        <omgdc:Bounds x="772" y="160" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="BPMNEdge_sid-604CE78D-58FC-495B-A3F4-F3634C685BBC" bpmnElement="sid-604CE78D-58FC-495B-A3F4-F3634C685BBC">
        <omgdi:waypoint x="130" y="178" />
        <omgdi:waypoint x="220" y="178" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0m254lp_di" bpmnElement="Flow_0m254lp">
        <omgdi:waypoint x="570" y="178" />
        <omgdi:waypoint x="772" y="178" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0jhlrng_di" bpmnElement="Flow_0jhlrng">
        <omgdi:waypoint x="320" y="178" />
        <omgdi:waypoint x="470" y="178" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

I have a problem while debugging

In the image above, he performs the delete operation, but I then query the data to see that he is still there. Why is this? Is this about business? But I didn’t add a transaction to the entire execution process.

I found that he failed to execute delete from ACT_RU_EXECUTION. These two data correspond to act_ru_task respectively. The data was not deleted and the act_ru_variable was not cleared. It may be related to the runtime task

Thank you for seeing the problem.

Tell me about my current solution。
The real error I found was that the act_ru_variable data was not correctly deleted when the act_ru_execution data was deleted。
runtimeService.createChangeActivityStateBuilder()
.moveExecutionsToSingleActivityId().This method call skips data where IS ACTIVE is 0.

Problems caused
act_ru_execution will have IS_ACTIVE_ temporary variable data that is not cleared