temporal.internal.sync.PotentialDeadlockException

Hi,

I have a temporal scheduler workflow running everyday and this workflow triggers another workflow on the basis of some checks implemented. this is how I have tried to trigger the workflow from inside my scheduler workflow:


public void deactivateInternalTenant(TenantMetadataTable tenant, String tenantId) {
  var workflowId = “DEACTIVATION.” + tenantId;
  TenantDeactivationWorkflow tenantDeactivationWorkflow =
          Workflow.newChildWorkflowStub(TenantDeactivationWorkflow.class,
                  ChildWorkflowOptions.newBuilder()
                                      .setWorkflowId(workflowId)
                                      .setNamespace(“internal_tenant_mapping”)
                                      .setTaskQueue(Constants.TENANT_DEACTIVATION_WF_QUEUE)
                                      .setWorkflowExecutionTimeout(Duration.ofMinutes(30))
                                      .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
                                      .setCancellationType(ChildWorkflowCancellationType.WAIT_CANCELLATION_REQUESTED)
                                      .build());
  WorkflowConfiguration workflowConfiguration = WorkflowConfiguration.builder()
                                                                     .immutableTenantId(tenant.getImmutableTenantId())
                                                                     .internalTenantId(tenant.getInternalTenantId())
                                                                     .userId(TENANT_SVC_DELETION_JOB)
                                                                     .tenantStatus(UclTenantMapping.TenantStatus.DEVELOPMENT)
                                                                     .uclFormationId(“ucl-formation-id”)
                                                                     .operation(TmOperation.UNASSIGN)
                                                                     .assignedTenant(AssignedTenant.builder()
                                                                                                   .applicationNamespace(“sap.bdcfos.testing”)
                                                                                                   .build())
                                                                     .receiverTenant(ReceiverTenant.builder()
                                                                                                   .uclAssignmentId(“ucl-assignment-id”)
                                                                                                   .build())
                                                                     .build();
  WorkflowRuntimeContext workflowRuntimeContext = WorkflowRuntimeContext.builder()
                                                                        .build();
  WorkflowContext workflowContext = new WorkflowContext();
  workflowContext.setWorkflowConfiguration(workflowConfiguration);
  workflowContext.setWorkflowRuntimeContext(workflowRuntimeContext);
  Async.procedure(tenantDeactivationWorkflow::deactivate, workflowContext);
  Workflow.getWorkflowExecution(tenantDeactivationWorkflow).get();
  log.info(“Spawned child workflow id: {} to deactivate tenant {}”, workflowId, tenantId);

}

But this logic throws an error which is something like this:

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
     at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.RuntimeException: WorkflowTask: failure executing SCHEDULED->WORKFLOW_TASK_STARTED, transition history is [CREATED->WORKFLOW_TASK_SCHEDULED]
     at io.temporal.internal.statemachines.StateMachine.executeTransition(StateMachine.java:163)
     at io.temporal.internal.statemachines.StateMachine.handleHistoryEvent(StateMachine.java:103)
     at io.temporal.internal.statemachines.EntityStateMachineBase.handleEvent(EntityStateMachineBase.java:84)
     at io.temporal.internal.statemachines.EntityStateMachineInitialCommand.handleEvent(EntityStateMachineInitialCommand.java:70)
     at io.temporal.internal.statemachines.WorkflowStateMachines.handleSingleEvent(WorkflowStateMachines.java:477)
     at  {detectionTimestamp=1753959843517, threadDumpTimestamp=1753959843552} 

workflow-method-ScheduledTenantDeletionWorkflow-2025-07-31T10:44:0...-01986014-e9a8-7766-948c-4eb404d8aa14
     at com.sap.bdc.fos.tenant.workflow.ScheduledTenantDeletionWorkflowImpl.deactivateInternalTenant(ScheduledTenantDeletionWorkflowImpl.java:90)
     at

What could be the reason behind this?

Hi,

not sure what the issue is, but it does not seem a PotentialDeadlockException from the stack trace

is deactivateInternalTenant and activity or the main workflow method?

This post Best way to create an async child workflow - #2 by maxim shows how to start workflows async if that is what you are trying to do.

What is exactly in line 90 (ScheduledTenantDeletionWorkflowImpl.java:90)?

Antonio

Hi @antonio.perez ,
Thank you for the response. Will check the post you mentioned.

line 90 has the workflow getting built like this:
var workflowId = “DEACTIVATION.” + tenantId;
TenantDeactivationWorkflow tenantDeactivationWorkflow =
Workflow.newChildWorkflowStub(TenantDeactivationWorkflow.class,
ChildWorkflowOptions.newBuilder()
.setWorkflowId(workflowId)
.setNamespace(“internal_tenant_mapping”)
.setTaskQueue(Constants.TENANT_DEACTIVATION_WF_QUEUE)
.setWorkflowExecutionTimeout(Duration.ofMinutes(30))
.setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
.setCancellationType(ChildWorkflowCancellationType.WAIT_CANCELLATION_REQUESTED)
.build());

the deactivateInternalTenant is the main workflow method.

Thanks @Neelofer

I still don’t understand how that line throws the error, does it happen consistently? could you share a reproduction?

Antonio