Azure/azure-functions-dotnet-worker

Function hangs on unhandled exception

mrpmorris opened this issue ยท 7 comments

Description

I noticed that some calls to my HttpTrigger were taking a long time. Upon investigation I discovered that a 3rd party library was throwing an exception that I wasn't handling.

It seems that if such an exception is encountered, the calling client is just left hanging.

Steps to reproduce

  1. New Azure Functions App with an HttpTrigger
  2. Change the handler code to throw new Exception("Unhandled exception thrown by someone else's library.");
  3. Run the app
  4. Open a browser
  5. Navigate to the endpoint for the HttpTrigger

Expected: The client request should end with a server 500 errror.
Actual: The client request remains open for a very long time.

FunctionApp25.zip

Hi @mrpmorris, what extension package versions are you using? We need more information to repro.

If you are using Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore, we've recently released a new version (1.3.0) with added improvements to our exception and timeout handling. Please let us know if it resolves your issue - if not, please share your extension packages, their versions, and your worker/sdk versions. Thanks!

@satvu Unfortunately that did not solve my problem.

I have attached repro source to the bottom of the ticket.

  1. Run app
  2. Navigate to the URL of the http trigger
  3. Watch the browser sit there waiting for a response

I've just discovered this happening in my own function that I've recently updated to the isolated runtime.

In my case, I'm using the [FromBody] attribute in my function and I experience the behaviour if I supply a request that cannot be deserialized correctly.

[Function("CreateThing")]
public async Task<IActionResult> CreateThingAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "things")] HttpRequestData request,
[Microsoft.Azure.Functions.Worker.Http.FromBody] ThingRequest thing) {
    // ...
}

I can see that there's a System.InvalidOperationException being thrown but the HttpRequest is never completed, so the request just sits and hangs until timeout.

@satvu

I ran into what I assume is the same issue after updating azure-functions-core-tools versions.
Azure/azure-functions-core-tools#3697
Please find reproduction steps there.
(Note that this issue is occurring even when using Extensions.Http.AspNetCore 1.3.1)

We are having this same issue we detected during the migration of our Azure Functions from .NET 6 In-process to .NET 8 Isolated worker. We are looking for a resolution before deploying it to production.
We could workaround with an ExceptionHandlingMiddleware.
@satvu is there any official workaround or a resolution for this?

Will update this thread again when the fix is officially released.

1.3.2 has been released, thanks all for the reports/repros.