Set HttpClient Timeout for Azure function app

huangapple go评论114阅读模式
英文:

Set HttpClient Timeout for Azure function app

问题

我有一个在Azure上运行的dotnet Function App,它使用HttpClient来调用另一个API,但在一段时间后超时(我认为是100秒,应该是默认值)。我已经尝试将timeout字段更新为30分钟或60分钟(例如httpClient.Timeout = TimeSpan.FromMinutes(30);),但这没有改变任何事情。

对于dotnet API,这个超时值是由服务器设置的,而不是代码3,对于我的API来说,这个工作得很好(我可以在dotnet API上下文中调用相同的代码,它可以正常工作),但我需要将它添加到我的函数应用上下文中。如果我理解不对,请纠正我,但函数应用没有Web.config文件,只使用应用设置/连接字符串,我找不到一个适用于此的应用设置。有没有办法绕过这个问题?

注意:这不是由于实际函数应用超时,我仍然可以在函数应用中运行代码,即使http客户端超时。问题是要为Http客户端专门配置执行超时,仅在函数应用上下文中

英文:

I have a dotnet Function App running on Azure which uses a HttpClient to call another API, but it times out after a bit (100 seconds I believe, which should be the default). I've tried updating the timeout field to 30 minutes or 60 minutes (e.g. httpClient.Timeout = TimeSpan.FromMinutes(30);) but this doesn't change anything.

For dotnet APIs, this timeout value is set by the server, not the code, which works fine for my API (I can call the same code in a dotnet API context and it works fine), but I need to add this to my function app context. Correct me if I'm wrong, but function apps don't have a Web.config file but only use app settings/connection strings and I couldn't find an app setting for this. Any way to get around this?

Note: This is not due to the actual function apps timing out, I can still run code in the function app after the http client times out. The issue is configuring execution timeout specifically for Http client, just within a function app context

答案1

得分: 0

我找到了一个解决方案,请按照这里的指南进行实施:https://thomaslevesque.com/2018/02/25/better-timeout-handling-with-httpclient/,以增加超时时间并设置每个请求的取消。

在我的情况下,我正在调用Azure上的另一个API,因此它有一个230秒的硬限制,但这仍然比100秒要好,并且实际上可以根据需要设置超时。

英文:

I found a solution, implement this guide here: https://thomaslevesque.com/2018/02/25/better-timeout-handling-with-httpclient/ to increase the timeout and set the cancel per-request

In my case, I'm calling another API on Azure so it has a hard limit of 230 seconds, but this is still better than 100 seconds and can actually set a timeout if I want.

答案2

得分: -1

Microsoft文档中提到,无论超时设置如何,HTTP触发函数的最大超时时间为230秒:
> 函数应用中函数的超时持续时间由host.json项目文件中的functionTimeout属性定义。<...>
无论函数应用超时设置如何,HTTP触发函数的响应时间最长为230秒,这是因为Azure负载均衡器的默认空闲超时。

从这个答案中看来,似乎无法扩展230秒的限制。

英文:

In Microsoft documentation it is mentioned that max timeout for http trigger function is 230 seconds regardless of timeout:
> The timeout duration for functions in a function app is defined by the functionTimeout property in the host.json project file. <...>
Regardless of the function app timeout setting, 230 seconds is the maximum amount of time that an HTTP triggered function can take to respond to a request. This is because of the default idle timeout of Azure Load Balancer.

From this answer it seems that 230 seconds limit cannot be extended.

huangapple
  • 本文由 发表于 2023年8月5日 03:44:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838775.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定