Share via

Azure function with Sendgrid output binding is timing out

Neščivera Ján (ERNI) 65 Reputation points
2026-02-05T09:07:48.9866667+00:00

We have an Nodejs Azure functions app (Node 20, programing model v3) that contains multiple functions. One of our functions uses Sndgrid output binding configured as follows:

{
  "name": "$return",
  "type": "sendGrid",
  "direction": "out",
  
  "from": "%SENDGRID_SENDER%"
}

The function is very simple, it just gathers recipient emails from a database and returns a simgle Mail object (from @sendgrid/helpers package). Just before the return mail; statement, we have a log statement that message is being sent.

This function however quite fequently times out (we have 10 minute limit). I would understand this if retrieval of recepient emails from database or producing email message would take a long time, but thats not the case. In all timeouted cases we can see the log statement that message is being sent (thats just before the return statement of the function). Therefore it seems to be timing out in the binding processing. Is that possible? Is there a way to diagnose this?

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


Answer accepted by question author

Pravallika KV 16,945 Reputation points Microsoft External Staff Moderator
2026-02-05T09:34:09.5133333+00:00

Hi @Neščivera Ján (ERNI),

Thanks for reaching out to Microsoft Q&A.

Your timeouts are happening after your code finishes because the SendGrid output binding executes after the return statement. In Azure Functions, output bindings execute after your function code returns. So even though your log appears just before return mail;, the SendGrid binding is still making the HTTP call to SendGrid.

On a Consumption plan, this call can occasionally hang due to limited outbound SNAT ports or transient network delays. The function invocation stays active while the binding runs, which explains why it eventually hits the 10-minute timeout.

Diagnosing this is difficult because the SendGrid output binding does not expose HTTP logs or errors, so Application Insights only shows the function timing out.

Solution:

The reliable solution is to stop using the output binding and call the SendGrid SDK directly using await sgMail.send(mail), which gives full control, proper error handling, logging, and avoids these hidden binding delays.

Hope this helps!


If the resolution was helpful, kindly take a moment to click on 210246-screenshot-2021-12-10-121802.pngand click on Yes for was this answer helpful. And, if you have any further query do let us know.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-02-05T09:08:02.6733333+00:00

    It sounds like you're experiencing timeouts during the processing of the SendGrid output binding in your Azure Function. Here are a few considerations and troubleshooting steps that might help you diagnose and resolve the issue:

    1. Long-running Functions: Ensure that your function is not inadvertently becoming long-running. Even if the email retrieval and message creation are quick, the binding itself might be taking time. Azure Functions can timeout if the overall execution exceeds the configured limit, which in your case is 10 minutes. Consider refactoring your function to ensure that it completes quickly and returns a response promptly.
    2. Background Tasks: If your function initiates any background tasks (like sending an email), ensure that these tasks are completed before the function returns. Azure Functions does not track background threads, and if your function returns before the SendGrid binding completes, it could lead to timeouts.
    3. Logging: Since you have a log statement before the return, check if there are any logs after that point which might indicate where the delay is occurring. This can help identify if the timeout is happening during the binding process.
    4. Binding Configuration: Review your SendGrid binding configuration to ensure that it is set up correctly. If there are any issues with the API key or the sender email, it could cause delays in processing.
    5. Retries and Visibility Timeout: If the SendGrid binding is failing and retrying, it could lead to timeouts. Check the visibility timeout settings and the maximum dequeue count for any related configurations that might affect the binding's behavior.
    6. Azure Function Plan: Ensure that your Azure Function is running on an appropriate hosting plan. If you are on a Consumption plan, consider switching to a Premium plan, which might provide better performance and reliability for your use case.

    By following these steps, you should be able to get more insight into the cause of the timeouts and potentially resolve the issue.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

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.