Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http Trigger Azure function returns 404 randomly

We have a .net core azure function on function runtime 3. This works perfectly fine ran locally and most of the time on our deployed app service. However we've experienced intermittent 404 responses for requests that go through perfectly fine at other times.

There's no entries appearing in our logs or application insights telemetry for the failing requests.

It feels a lot like this issue on the azure-function-host github project: https://github.com/Azure/azure-functions-host/issues/5247 though that's targeting functions runtime 1 or 2.

Has anyone had similar issues or know of any way to get additional log info that might highlight what problem we're running into.

like image 807
Ben Ford Avatar asked May 03 '26 16:05

Ben Ford


1 Answers

That might happen during scaling out or your function app about to change the server from one to another (for some reason). That's the actually cons of serverless applications.

But what I can suggest to you is:

  • Create HeartBeat Function similar to this:

    private readonly IAsyncRepository<Business> _businessAsyncRepository;
    
    public HeartBeat(IAsyncRepository<Business> businessAsyncRepository)
    {
        // Your all DI injections are here
        _businessAsyncRepository = businessAsyncRepository;
    }
    
    [FunctionName(nameof(HeartBeat))]
    public async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
        ILogger log)
    {
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        return new OkObjectResult("OK");
    }
    

And then create availability test on Application Insights and call the HeartBeat.

enter image description here

This will also give you a warm instance of Azure Functions at all time. But obviously you spend your 1m free call on consumption plan every time you call the heartbeat depending on how frequently you call the AF.

like image 77
Mehmet Taha Meral Avatar answered May 06 '26 07:05

Mehmet Taha Meral