Azure Function在App服务计划上两次调用了自己 [英] Azure Function is calling itself twice on App service plan

查看:105
本文介绍了Azure Function在App服务计划上两次调用了自己的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的azure函数中有以下代码,手动超时为10分钟.

I have the following code in my azure function with 10 minutes manual timeout.

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");
    try
    {
        TimeSpan ts = TimeSpan.FromMinutes(1);
        for(int i=0;i<10;i++)
        {
            await Task.Delay(ts);
            log.Info(String.Format("After 1 Min Delay {0}",i));
        }
        log.Info(String.Format("After 10 Min Delay "));
        return req.CreateResponse(HttpStatusCode.OK);
    }
    catch (Exception e)
    {
        log.Info(String.Format("exception: {0}", e));
        return req.CreateResponse(HttpStatusCode.BadRequest);
    }
}

当我在Azure中运行上述功能时,我看到该功能在3分钟后创建了一个新实例. (请查看下面的日志)

when I run the above function in Azure, I see the function creates a new instance after 3 minutes. (check the below log)

2018-05-15T11:12:42  Welcome, you are now connected to log-streaming service.
2018-05-15T11:12:55.826 [Info] Function started (Id=f25e0bbd-7103-4823-b8f1-ef28888f7007)
2018-05-15T11:12:55.826 [Info] C# HTTP trigger function processed a request.
2018-05-15T11:13:55.844 [Info] After 1 Min Delay 0
2018-05-15T11:14:55.857 [Info] After 1 Min Delay 1
2018-05-15T11:15:55.862 [Info] After 1 Min Delay 2
2018-05-15T11:16:47.385 [Info] Function started (Id=7371ed94-9b62-40cc-bec0-00b8d5e0a250)
2018-05-15T11:16:47.385 [Info] C# HTTP trigger function processed a request.
2018-05-15T11:16:55.879 [Info] After 1 Min Delay 3
2018-05-15T11:17:47.395 [Info] After 1 Min Delay 0
2018-05-15T11:17:55.883 [Info] After 1 Min Delay 4
2018-05-15T11:18:47.400 [Info] After 1 Min Delay 1
2018-05-15T11:18:55.899 [Info] After 1 Min Delay 5
2018-05-15T11:19:47.411 [Info] After 1 Min Delay 2
2018-05-15T11:19:55.914 [Info] After 1 Min Delay 6
2018-05-15T11:20:47.413 [Info] After 1 Min Delay 3
2018-05-15T11:20:55.920 [Info] After 1 Min Delay 7
2018-05-15T11:21:47.416 [Info] After 1 Min Delay 4
2018-05-15T11:21:55.930 [Info] After 1 Min Delay 8
2018-05-15T11:22:47.436 [Info] After 1 Min Delay 5
2018-05-15T11:22:55.936 [Info] After 1 Min Delay 9
2018-05-15T11:22:55.936 [Info] After 10 Min Delay
2018-05-15T11:22:55.936 [Info] Function completed (Success, Id=f25e0bbd-7103-4823-b8f1-ef28888f7007, Duration=600105ms)
2018-05-15T11:23:47.447 [Info] After 1 Min Delay 6
2018-05-15T11:24:47.452 [Info] After 1 Min Delay 7
2018-05-15T11:25:47.467 [Info] After 1 Min Delay 8
2018-05-15T11:26:47.478 [Info] After 1 Min Delay 9
2018-05-15T11:26:47.478 [Info] After 10 Min Delay
2018-05-15T11:26:47.478 [Info] Function completed (Success, Id=7371ed94-9b62-40cc-bec0-00b8d5e0a250, Duration=600086ms)

在上面的日志中,您可以看到azure函数正在调用两次,并且在完成执行后还会给出错误(500:内部服务器错误).

In above log, you can see that azure function is calling twice and also it gives the error (500: internal server error) and after it completes its execution.

推荐答案

这与http请求超时和重试有关.

It is about http request timeout and retry.

当我直接在门户网站中运行该函数时,将在像@Sumit和@Joey看到将近4m后再次调用它.我将Delay减少到10s,该函数仅触发一次并返回200.

When I run the function directly in portal, it will be called again after nearly 4m like @Sumit and @Joey have seen. I decrease the Delay to 10s, and the function is only triggered once and returns 200.

尝试使用邮递员发布请求,这一次该功能仅在以下响应消息中被触发一次.

Try to use postman to post request, this time the function is triggered only once with response message below.

正如我们在代码中看到的那样,只有10m的过程完成后,才会发送回响应.超出了超时设置,并且根据设计,门户网站发布的请求似乎将在超时后重试.

As we can see in the code, no response sent back until 10m process finished. It is beyond the timeout setting and it seems by design that request posted by portal will be retried after timeout.

更新

Azure功能是一种Azure Web App,请参见 Azure Web应用程序超时设置为230秒.

Azure function is one kind of Azure Web App, see Azure Web App time out 230s setting.

对于未发送回任何数据的请求,会有230秒(即不到4分钟)的超时时间.在那之后,客户端获得了您看到的500,即使实际上请求被允许继续服务器端

There is a 230 second (i.e. a little less than 4 mins) timeout for requests that are not sending any data back. After that, the client gets the 500 you saw, even though in reality the request is allowed to continue server side

这篇关于Azure Function在App服务计划上两次调用了自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆