简体   繁体   中英

TimeoutAttribute doesn't work for Azure function app

I'd like to limit the execution time of the azure function, and added the TimeoutAttribute on it as the code below.

    [FunctionName("Func2")]
    [Timeout("00:00:02", TimeoutWhileDebugging = true)]
    public static void Run([TimerTrigger("*/5 * * * * *")] TimerInfo myTimer, ILogger log)
    {
        log.LogInformation($"hi...");

        int length = 10;
        for (int i = 0; i < length; i++)
        {
            log.LogInformation($"looping {i + 1}...");
            //System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
            System.Threading.Tasks.Task.Delay(3000).Wait();
        }
    }

I ran the code in visual studio 2019 locally. And I expected the above code times out in 2 seconds, but it ran the complete 10 loops without any error.

Is there any issue above?

This is looking like a bug and reproducible, I can also reproduce this locally

Github issues #1900

At the moment this is progressing through triage and has the Bug tag.

Note : At this stage there are no known workarounds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM