OzTrak
OzTrak

Reputation: 115

Azure Function App Returning 499 Error When Executing OKObjectResult - Sometimes

I have a number of functions in a .Net 9 function app, running under the isolated model, that occassionally return a 499 error AFTER the actual work of the function has completed.

The function looks like this:

public async Task<IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)

I can see from the logs that the function has performed its task correctly and is then attempting to return an OKObjectResult - this is when the error occurs.

Here's the end of the log trace that shows the error:

Log tract showing error

I have noted, in the list of invocations, that the invocations that have returned an error are fairly widely spaced apart. The function, when it executes, does access a database which may take a moment to spin up. Yet, when looking at the time things take, the database calls take about 2 seconds to complete and the whole function is done in less that 4 seconds. I would have thought that this was plenty of time for the function to complete and return a valid result. The calling site (JotForm in this case) say they wait 30 seconds for a response, so they should still be listening for a response.

Here's a sample of the timing of the invocations:

List of invocations

The more I think about it, it appears to be a timing issue of some sort - but how to fix it?

Thanks Gordon

Upvotes: 0

Views: 77

Answers (1)

Pravallika KV
Pravallika KV

Reputation: 8694

As mentioned in MSDOC, an HTTP 499 error occurs if a client request is closed abruptly before the server finished responding.

  • This happens when a large response is returned to the client, and the client might have closed or refreshed the application before the server finished sending a large response.
  • When the timeout on the client side is low and doesn't wait long enough to receive the response from server.

To resolve this, I would suggest increasing the timeout on the client by adding functionTimeout setting in host.json.

{
    "functionTimeout": "00:30:00"  // 30 minutes
}

host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      },
      "enableLiveMetricsFilters": true
    }
  },
  "functionTimeout": "00:30:00"
}
  • Review the function's async behavior and make sure all asynchronous tasks are being awaited properly.

  • Run the function locally and check if you get the same error.

  • Go to FunctionApp=>Monitoring=>LogStream, review the logs for detailed error

enter image description here

Upvotes: 0

Related Questions