Can't change timeout for HttpClient when running Azure function app

Reid Moffat 0 Reputation points
2023-08-04T20:32:45.09+00:00

I have a C# function app on azure that calls another API using the HttpClient class, but it keeps timing out and I can't find how to change the timeout time from the default (I think 100 seconds or 2 minutes?). The API endpoint I'm calling is expected to take a while, it's not an issue with the API as I've confirmed the api is working ok.

I've tried changing the Timeout property of HttpClient (tried half an hour and an hour) but this doesn't do anything. Stack overflow says the timeout is defined by the server, not the code, and you need to add a executionTimeout property to the Web.config to change the max timeout; however, this is a function app that doesn't have a Web.config and the executionTimout needs an xml entry in this file, not an environment variable.

How can I increase the HttpClient timeout time? Note that my function app (v2) isn't timing out, just specifically the call to another API that is and throws an exception.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Developer technologies C#
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-08-04T20:40:21.81+00:00

    azure functions have a limited cpu and runtime. you can not extend this. you can switch hosting technology or better design the system

    you could change your api to return a unique id right away, and do web hook callback with the id when done. this web hook can then complete the transaction call, or call another azure function.

    you could also do polling for completion, if api can not call web hooks


  2. MayankBargali-MSFT 70,936 Reputation points Moderator
    2023-08-07T05:03:58.2333333+00:00

    @Reid Moffat Thanks for reaching out and sharing more details.

    If a function that uses the HTTP trigger doesn't complete within 230 seconds, the Azure Load Balancer will time out and return an HTTP 502 error. The function will continue running but will be unable to return an HTTP response. For long-running functions, we recommend that you follow async patterns and return a location where you can ping the status of the request. For information about how long a function can run, see Scale and hosting - Consumption plan.

    The same is documented here

    Let me know if you have any queries or concerns.


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.