4 Minute Delay when Invoking HTTP Triggered Azure Function from Another Azure Function

Greyson Maddox 0 Reputation points
2023-08-16T22:27:55.42+00:00

As the title states, I have a function in Azure that sends an HTTP Post request to another function’s endpoint every 5 minutes (in order to prevent cold start issues). However, for some reason every time I send this post request, there is a 4 minute (240000 MS) delay in Azure between invocation and the first line of code being executed. Does Azure functions have some specific issue that I don’t know about when being invoked from a separate function in the same function app or could this be something different? Code is below

Code that invokes the delayed function:

import logging
import requests
import azure.functions as func
import json


def main(mytimer: func.TimerRequest) -> None:
    url = '{MAIN FUNCTION URI}'
    payload = {"event":{"bot_id":"1","user":"TEST","channel":"TEST","team":"TEST","channel_type":"TEST"}}
    logging.info("Invoking the Endpoint")
    requests.post(url, data=json.dumps(payload))
    logging.info('Function Warmer Executed Successfully')
import logging
import azure.functions as func
from azure.storage.queue import QueueClient
import os
import base64

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info(req.get_body())
    req_body = req.get_json()
    logging.info(req_body['event'])
    if 'challenge' in req_body:
        return func.HttpResponse(req_body['challenge'])
    event = req_body['event']
    user = event.get('user')
    channel = event.get('channel')
    team = event.get('team')
    text = event.get('text')
    event_type = event.get('channel_type')
    if 'bot_id' not in event:
        storage_acct_name = os.environ['STORAGE_ACCT_NAME']
        storage_acct_token = os.environ['STORAGE_ACCT_TOKEN']
        storage_account_url = f"https://{storage_acct_name}.queue.core.windows.net"
        queue_name = 'slackmessages'
        if event_type == 'channel':
            payload = f'{{"user": "{channel}", "text": "{text}"}}'
        elif event_type == 'team':
            payload = f'{{"user": "{team}", "text": "{text}"}}'
        elif event_type == 'im':
            payload = f'{{"user": "{user}", "text": "{text}"}}'
        encoded_message = base64.b64encode(payload.encode()).decode()
        queue_service = QueueClient(account_url=storage_account_url, queue_name=queue_name, credential=storage_acct_token)
        queue_service.send_message(encoded_message)
    logging.info('Python HTTP trigger function processed a request.')
    return func.HttpResponse(
        "This HTTP triggered function executed successfully. The other request is now being processed",
        status_code=200
    )
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2023-08-17T08:23:39.1+00:00

    @Greyson Maddox Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    experiencing a 4-minute delay when invoking an HTTP triggered Azure Function from another Azure Function. They are sending an HTTP Post request to another function's endpoint every 5 minutes to prevent cold start issues.

    Azure Functions are designed to be event-driven and can be triggered by various events, including HTTP requests. When an HTTP request is received, the Azure Function is invoked, and the code is executed. However, there can be some delay between the invocation and the first line of code being executed, which can be caused by various factors, including cold start issues, network latency, and other factors.

    1. Could you please enable the Application insight logs for the FunctionApp and check if there are any invocation exceptions. You can enabled the AppInsights as explained here. You can enabled the AppInsights as explained here.
    2. Please check the Function App detectors by navigating to the Diagnose and Solve Problems section in the Azure Portal for the Functions as shown below: You can rely on the Function Execution Performance setting:

    enter image description here

    1. You can also query the FunctionLogs as shown below:

    enter image description here

    More Info here.

    On a side note:

    • Consider using Azure Functions Premium plan, which provides faster cold start times and improved performance for HTTP-triggered functions and it uses Perpetually warm instances to avoid any cold start.
    • You can also check if using Dedicated app service plan is feasible. When running in a Dedicated plan, the Functions host can run continuously, which means that cold start isn't really an issue. You have the AlwaysOn feature to avoid the cold start.

    Note: If none of the above steps help, Please share the below details over an email at AzCommunity@microsoft.com ( with subject "Attn: Naveen") and include the below details:

    • Your Azure Function Name
    • You Azure Function App resource URI in below format: /subscriptions/XXXXXXXXXX/resourceGroups/XXXXXX/providers/Microsoft.Web/sites/XXXXXX
    • Most recent UTC time of the actual issue where you received the 4 minutes delay:

    I will look at the backend logs to identify the root cause.

    **
    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


Your answer

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