You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何启用专用端点的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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 02:25:20