microsoft / durabletask-java

Java SDK for Durable Functions and the Durable Task Framework
MIT License
13 stars 7 forks source link

Fix orchestrator has already completed issue #139

Closed kaibocai closed 1 year ago

kaibocai commented 1 year ago

Issue describing the changes in this PR

resolves 138

Pull request checklist

Additional information

Additional PR information

For a sample orchestration function

    @FunctionName("EternalOrchestrator")
    public void startWorkflowSchedule(@DurableOrchestrationTrigger(name = "runtimeState") TaskOrchestrationContext ctx) 
     {
        LOGGER.info("Doing something in the cleanup loop");

        ctx.createTimer(Duration.ofSeconds(60)).await();

        ctx.continueAsNew(null);
     }

The invocation process complete twice:

  1. First time at https://github.com/microsoft/durabletask-java/blob/4a204cd238849d183581f7b73bcf86691ce97436/client/src/main/java/com/microsoft/durabletask/OrchestrationRunner.java#L66 ctx.complete(null)
  2. Second time at https://github.com/microsoft/durabletask-java/blob/4a204cd238849d183581f7b73bcf86691ce97436/client/src/main/java/com/microsoft/durabletask/TaskOrchestrationExecutor.java#L60 This is the one causing exception as isCompleted flag is already set to true at the first complete.

Update the condition check at 2 to avoid repeating complete.