Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to schedule a terminated orchestration has no effect #3025

Open
andystaples opened this issue Feb 4, 2025 · 0 comments
Open

Attempting to schedule a terminated orchestration has no effect #3025

andystaples opened this issue Feb 4, 2025 · 0 comments

Comments

@andystaples
Copy link
Contributor

Description

When calling TerminateInstanceAsync() in dotnet-isolated (and probably inprocess too) on an orchestration ID that is scheduled to run in the future, the logging reports that the instance was terminated, but it remains in the Pending state and will still run after it's scheduled date.

Expected behavior

Terminating a scheduled orchestration should move it to the Terminated state and prevent it from running when it was scheduled.

Actual behavior

Terminating a scheduled orchestration logs that the terminate operation was unsuccessful, but has no effect on the orchestration.

Relevant source code snippets

        [Function("TerminateInstance")]
        public static async Task<HttpResponseData> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
            [DurableClient] DurableTaskClient client,
            string instanceId)
        {
            string reason = "Long-running orchestration was terminated early.";
            try 
            {
                await client.TerminateInstanceAsync(instanceId, reason);
                return req.CreateResponse(HttpStatusCode.OK);
            }
            catch (RpcException ex) 
            {
                var response = req.CreateResponse(HttpStatusCode.BadRequest);
                response.Headers.Add("Content-Type", "text/plain");
                await response.WriteStringAsync(ex.Message);
                return response;
            }
        }

        [Function("HelloCities_HttpStart_Scheduled")]
        public static async Task<HttpResponseData> HttpStartScheduled(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
            [DurableClient] DurableTaskClient client,
            FunctionContext executionContext,
            DateTime scheduledStartTime)
        {
            ILogger logger = executionContext.GetLogger("HelloCities_HttpStart");

            var startOptions = new StartOrchestrationOptions(StartAt: scheduledStartTime);

            // Function input comes from the request content.
            string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
                nameof(HelloCities), startOptions);

            logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

            // Returns an HTTP 202 response with an instance management payload.
            // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
            return await client.CreateCheckStatusResponseAsync(req, instanceId);
        }

Known workarounds

Waiting until the orchestration begins running to terminate it.

App Details

Latest Durable worker extension **1.2.2/dotnet-isolated/FunctionsV4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant