Getting Unexpected end of request content error in HTTPStarter based azure durable function app

Nirali Shah 156 Reputation points
2025-03-18T12:06:16.26+00:00

We have created a HTTPStarter based azure durable function app. In this, we are getting 499 (Unexpected end of request content) error frequently between the successful executions.

When request is sent to the function app via webhook it results in error sometime where only 1 error log is available suggesting "Unexpected end of request content."

Function app is implemented in python and we have added the try-except block but no log is coming from there, so the exception is thrown by the function runtime as it is decoding it for the http-trigger.

FYI, The function app is running on a Linux Consumption plan.

Can anyone suggest the solution for this or any workaround to avoid the 499 error?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2025-04-02T08:15:26.57+00:00

    Hi Nirali Shah,

    The 499 error is a client-side problem, which means the client is the one closing the connection prematurely before the server could complete the response or the server is not receiving the entire body of the request sent by webhook before the connection is closed.

    If your Azure Function is taking a long time to complete, you can increase the functionTimeout setting in the host.json file.

    • Consumption Plan: Up to 5 minutes by default, extendable to 10 minutes.

    host.json:

    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
          }
        }
      },
      "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[4.*, 5.0.0)"
      },
      "functionTimeout":"00:10:00"
    }
    

    I have tested with below code and it worked:

    Http Starter:

    import inspect
    import json
    import logging
    import azure.durable_functions as df
    import azure.functions as func
    
    
    applogger = logging.getLogger("azure.functions")
    LOGS_STARTS_WITH = "LOG_PREFIX"
    
    def get_data_from_request_body(request):
        """Get data from request body.
        Args:
            request (func.HttpRequest): Azure function HttpRequest class object
        """
        __method_name = inspect.currentframe().f_code.co_name
        try:
            data = request.get_json()
            json_data = json.dumps(data)
            return json_data
        except ValueError as value_error:
            applogger.error("{}(method={}) {}".format(LOGS_STARTS_WITH, __method_name, value_error))
        except Exception as err:
            applogger.error("{}(method={}) {}".format(LOGS_STARTS_WITH, __method_name, err))
    
    async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
        """
        Start the execution.
        Args:
            req (func.HttpRequest): To get data from request body pushed by webhook
        Returns:
            func.HttpResponse: Status of Http request process (successful/failed).
        """
        __method_name = inspect.currentframe().f_code.co_name
        try:
            applogger.debug("{} HttpStarter Function Called.".format(LOGS_STARTS_WITH))
            data = get_data_from_request_body(req)
            
            if data:
                client = df.DurableOrchestrationClient(starter)
                instance_id = await client.start_new(
                    req.route_params["functionName"], client_input=data
                )
                applogger.info(
                    "{} Started orchestration with ID = '{}'.".format(
                        LOGS_STARTS_WITH, instance_id
                    )
                )
                
                body = "Data Received successfully via Webhook."
                return func.HttpResponse(
                    body=body,
                    status_code=200,
                    headers={"Content-Length": str(len(body))},
                )
            else:
                applogger.info("{}(method={}) No required data found.".format(LOGS_STARTS_WITH, __method_name))
                body = "No required data found."
                return func.HttpResponse(
                    body=body,
                    status_code=202,
                    headers={"Content-Length": str(len(body))},
                )
        except Exception as err:
            body = "Error: {}".format(err)
            return func.HttpResponse(
                body=body,
                status_code=400,
                headers={"Content-Length": str(len(body))},
            )
    

    Orchestrator Function:

    import logging
    import json
    from azure.durable_functions import DurableOrchestrationContext, Orchestrator
    
    def orchestrator_function(context: DurableOrchestrationContext):
        result1 = yield context.call_activity('Hello', "Tokyo")
        result2 = yield context.call_activity('Hello', "Seattle")
        result3 = yield context.call_activity('Hello', "London")
        return [result1, result2, result3]
    main = Orchestrator.create(orchestrator_function)
    

    Activity Function(Hello):

    import logging
    
    def main(name: str) -> str:
        return f"Hello {name}!"
    

    Able to run the function in portal:

    Sample Payload:

    {
      "event": "webhook_event",
      "data": {
        "id": 12345,
        "name": "Sample Event",
        "timestamp": "2025-04-02T12:34:56Z",
        "details": "Some detailed information about the event"
      }
    }
    

    enter image description here

    enter image description here

    Hope this helps.

    If you have any other questions, please let me know. We will be glad to assist you with the further resolution.

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.