azure-functions-durable-extension: Isolated Process with DurableClient and ASP.NET Core integration will throw exception on CreateCheckStatusResponse
Description Packages:
- Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore v1.1.1
- Microsoft.Azure.Functions.Worker.Extensions.DurableTask v1.1.0
When using the version of the functions packages that provides ASP.NET Core integration and DurableTaskClient, the method CreateCheckStatusResponse will throw an InvalidOperationException because the implementation writes to the HttpResponseData synchronous
Expected behavior There should be no exception thrown, however as synchronous writing is not allowed since ASP.NET Core 3+ a Async version will be needed to be exposed.
Actual behavior System.InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead
Result: An unhandled exception occurred.
Exception: System.AggregateException: One or more errors occurred. (Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.)
---> System.InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at Azure.Core.Serialization.JsonObjectSerializer.Serialize(Stream stream, Object value, Type inputType, CancellationToken cancellationToken)
at Microsoft.Azure.Functions.Worker.DurableTaskClientExtensions.CreateCheckStatusResponse(DurableTaskClient client, HttpRequestData request, String instanceId, HttpStatusCode statusCode, CancellationToken cancellation) in /_/src/Worker.Extensions.DurableTask/DurableTaskClientExtensions.cs:line 97
at Microsoft.Azure.Functions.Worker.DurableTaskClientExtensions.CreateCheckStatusResponse(DurableTaskClient client, HttpRequestData request, String instanceId, CancellationToken cancellation) in /_/src/Worker.Extensions.DurableTask/DurableTaskClientExtensions.cs:line 34
Relevant source code snippets
[Function("SimpleHttpTriggerHttpData")]
public async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req,
[DurableClient] DurableTaskClient durableClient)
{
return durableClient.CreateCheckStatusResponse(req, "FakeId"); //Will result in exception
}
Known Workarounds The following configuration is possible, however this would be rather avoided
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
Other information
When using ASP.NET Core integration it would be nice to also have a CreateCheckStatusResponse version that accepts HttpRequest and returns an ActionResult to keep it more consistent with the HttpTriggers.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (6 by maintainers)
I would like to reopen this. I don’t think issue should be closed when default scafoldding for durable function in .NET Core Isolated project yields exeception and requires workarounds. This should be addressed. As a programmer I want the default setup to work. Seeing red error messages right after starting the sample project while following documentation is really not good user experience and if I was new to the technology I would be really questioning it
Create a new .NET 8 Durable Functions Orchestration project in VS 17.9.4. Then call Function1_HttpStart from a REST client. It will fail with the error described above.
Side-note: I can’t figure out a way to unit test Function1_HttpStart. An example would be great!
Honestly, you follow official documentation on how to create a new Durable Function which tells you to trigger the function through postman and you receive errors and status code 500, made me rethink what I am doing wrong and waste time on googling until I found this issue which is somehow closed.
Just confirming that as of 1.1.2, there’s a
CreateCheckStatusResponseAsyncthat can be used. I believe the team is working on fixing the default templates to use the correct API.Here’s what I got working after updating my nuget package references.
I was able to get it to work following the instructions at this link: https://github.com/Azure/azure-functions-templates/pull/1513
But the final fix was to replace the whole line of code from this:
“return client.CreateCheckStatusResponse(req, instanceId);”
to this:
“return await client.CreateCheckStatusResponseAsync(req, instanceId);”
I added “await” and that got the code working.
Yeah we dropped the ball on this one, my apologies for not realizing the templates had stopped working; I’m looking to follow up with the tooling teams to understand the existing template validation flow did not catch this.
I think part of the confusion, on our end, was that it wasn’t fully clear (at least to me) that this exception was getting triggered with the templates. I’m not sure that this was the case when this GitHub issue first got created, but it is certainly the issue now.
In any case, I’ve fixed our templates here and will be following up with the VS and VSCode teams to make sure these get shipped asap. In the meantime, it might be good to create some kind of pinned comment flagging this issue. I don’t believe this thread is the right thread to pin or re-open, but instead we should create one talking specifically about templates. I’ll look to follow up - cc/ @lilyjma
We’ve been using function apps for about two years now. If I were evaluating them today, seeing the VS template fail and needing to pour through all this just to get a base example to work would have ruined my enthusiasm for Azure functions. Right now we’re migrating from .Net 6 to 8, and I’m seeing this issue. The recommended workaround is also not a recommended approach to asynchronous.
For anyone interested, here’s my simple and ingenious workaround.
Hi @MarekLani - noted on the feedback, I agree the default set up should work; but I’m trying to make sure we’re talking about the same “default” set up.
Can you please help me understand what’s the sample project you’re using that’s leading to this “out of the box” exception? Some links to the docs or samples that are yielding this would help. Thanks!
@prashantagrawalcrowe There are three work arounds for now:
HttpRequestData/HttpResponseData. The following copied version from the package source will work with the first work-around, however keep in mind that this will need to do reflection at a point due to the need to access an internal property. So you will need to keep an eye out on this repo all the time to ensure the reflection will work and if any changes have been made.HttpRequestandIActionResult. The same applies as for point 2. It still needs to do reflection due to the need to access an internal property. So you will need to keep an eye out on this repo all the time to ensure the reflection will work and if any changes have been made.