microsoft / durabletask-java

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

Durable Task Client Wait for Instance Completion Failure - UNKOWN #159

Closed jsabev closed 1 year ago

jsabev commented 1 year ago

The waitForInstanceCompletion method in com.microsoft.durabletask.DurableTaskClient throws io.grpc.StatusRuntimeException: UNKNOWN: Exception was thrown by handler on call.

Example workflow

public class WaitForOrchestrationResults {

    @FunctionName("StartDurableOrchestrationWait")
    public HttpResponseMessage startOrchestrator(
            @HttpTrigger(name = "req", methods = {HttpMethod.GET}) HttpRequestMessage<Optional<String>> req,
            @DurableClientInput(name = "durableContext") DurableClientContext durableClientContext,
            final ExecutionContext context) {

         try(DurableTaskClient client = durableClientContext.getClient()){
             String instanceId = client.scheduleNewOrchestrationInstance("waitOrchestration", req);
             final OrchestrationMetadata orchestrationMetadata = client.waitForInstanceCompletion(instanceId, Duration.ofMinutes(10), true);
             return req.createResponseBuilder(HttpStatus.OK).body(orchestrationMetadata.getSerializedOutput()).build();
         } catch (Exception e) {
            e.printStackTrace();
            return req.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()).build();
         }
    }

    @FunctionName("waitOrchestration")
    public String orchestrationExtractXML(
            @DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx) {

        final Duration duration = Duration.ofSeconds(30);

        ctx.createTimer(duration).await();

        return duration.toString();
    }
}

Expected Result

The http call returns with status 200 after 30 seconds

Actual result

The http call returned with status 500

Full stack trace:

[2023-07-27T17:54:42.153Z] io.grpc.StatusRuntimeException: UNKNOWN: Exception was thrown by handler.
[2023-07-27T17:54:42.153Z]  at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:271)
[2023-07-27T17:54:42.153Z]  at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:252)
[2023-07-27T17:54:42.153Z]  at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:165)
[2023-07-27T17:54:42.153Z]  at com.microsoft.durabletask.implementation.protobuf.TaskHubSidecarServiceGrpc$TaskHubSidecarServiceBlockingStub.waitForInstanceCompletion(TaskHubSidecarServiceGrpc.java:1130)
[2023-07-27T17:54:42.153Z]  at com.microsoft.durabletask.DurableTaskGrpcClient.waitForInstanceCompletion(DurableTaskGrpcClient.java:189)
[2023-07-27T17:54:42.153Z]  at ca.qc.caij.ddc.azurehandlers.WaitForOrchestrationResults.startOrchestrator(WaitForOrchestrationResults.java:28)
[2023-07-27T17:54:42.153Z]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2023-07-27T17:54:42.160Z]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[2023-07-27T17:54:42.160Z]  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2023-07-27T17:54:42.161Z]  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[2023-07-27T17:54:42.161Z]  at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22)
[2023-07-27T17:54:42.161Z]  at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:22)
[2023-07-27T17:54:42.161Z]  at com.microsoft.azure.functions.worker.chain.FunctionExecutionMiddleware.invoke(FunctionExecutionMiddleware.java:19)
[2023-07-27T17:54:42.161Z]  at com.microsoft.azure.functions.worker.chain.InvocationChain.doNext(InvocationChain.java:21)
[2023-07-27T17:54:42.161Z]  at com.microsoft.durabletask.azurefunctions.internal.middleware.OrchestrationMiddleware.invoke(OrchestrationMiddleware.java:29)
[2023-07-27T17:54:42.161Z]  at com.microsoft.azure.functions.worker.chain.InvocationChain.doNext(InvocationChain.java:21)
[2023-07-27T17:54:42.161Z]  at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:125)
[2023-07-27T17:54:42.161Z]  at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:34)
[2023-07-27T17:54:42.162Z]  at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2023-07-27T17:54:42.162Z]  at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
[2023-07-27T17:54:42.162Z]  at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:94)
[2023-07-27T17:54:42.162Z]  at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2023-07-27T17:54:42.162Z]  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2023-07-27T17:54:42.162Z]  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2023-07-27T17:54:42.162Z]  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2023-07-27T17:54:42.162Z]  at java.base/java.lang.Thread.run(Thread.java:829)
[2023-07-27T17:54:42.176Z] Function "StartDurableOrchestrationWait" (Id: 26f09279-edbb-4292-8b4c-5ce68d634f36) invoked by Java Worker
[2023-07-27T17:54:42.252Z] Executing 'Functions.waitOrchestration' (Reason='(null)', Id=f33d8ea9-293c-4fc7-83da-7634640ef23a)
[2023-07-27T17:54:42.289Z] Function "waitOrchestration" (Id: f33d8ea9-293c-4fc7-83da-7634640ef23a) invoked by Java Worker
[2023-07-27T17:54:42.324Z] Executed 'Functions.StartDurableOrchestrationWait' (Succeeded, Id=26f09279-edbb-4292-8b4c-5ce68d634f36, Duration=1720ms)
[2023-07-27T17:54:42.324Z] Executed 'Functions.waitOrchestration' (Succeeded, Id=f33d8ea9-293c-4fc7-83da-7634640ef23a, Duration=93ms)
kaibocai commented 1 year ago

Hi @jsabev, this is a duplicate issue that already been fixed with the latest durable SDK, for more info please reference here https://github.com/microsoft/durabletask-java/issues/140