为何启用专用端点的Azure Function HttpTrigger超5秒返回500错误?
Azure Function 启用专用端点后长时运行返回500错误
- HttpTrigger类型Azure Function,本地运行时长超过5秒完全正常,但部署到**启用Private Endpoints(专用端点)**的FunctionApp时,返回“(500) Internal Server Error”
- 实际业务函数未使用
Thread.Sleep,仅运行时长超过5秒就触发该问题
复现失败的代码(运行时长7秒)
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.Extensions.Logging; using System.Threading; using System.Threading.Tasks; namespace MyTest.TestFunction { public class TestFunction { [FunctionName("TestFunction")] public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Before sleep"); Thread.Sleep(7000); log.LogInformation("After sleep"); return new OkObjectResult($"Hello"); } } }
复现成功的代码(运行时长2秒)
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.Extensions.Logging; using System.Threading; using System.Threading.Tasks; namespace MyTest.TestFunction { public class TestFunction { [FunctionName("TestFunction")] public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Before sleep"); Thread.Sleep(2000); log.LogInformation("After sleep"); return new OkObjectResult($"Hello"); } } }
host.json 配置
{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "functionTimeout": "00:15:00", }
内容的提问来源于stack exchange,提问作者Tobi
相关产品推荐
相关产品推荐

