1

I am running a web job under my web app (App Service) in Premium tier. It calls a REST API endpoint, which takes a long time to return response. The web job is getting aborted after 20 minutes, but according to the documentation a web job can run a long running task in background. That doesn't seems to be working as expected.

Is there any max timeout specified for web job function?

The code:

public async Task<HttpResponseMessage> GetAsync(Uri requestUrl)
{
    _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GetAadAuthentication().AccessToken);
    var httpResponse = await _httpClient.GetAsync(requestUrl);
    if (!httpResponse.IsSuccessStatusCode)
    {
        ProcessFailedRequest(httpResponse);
    }

    return httpResponse;
}

Exception log:

[05/26/2017 21:28:01 > 6e349c: ERR ] Unhandled Exception: System.Threading.Tasks.TaskCanceledException: A task was canceled.
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at Util.testWebClient.<GetAsync>d__12.MoveNext() in d:\test\Util\testWebClient.cs:line 99
[05/26/2017 21:28:01 > 6e349c: ERR ] --- End of stack trace from previous location where exception was thrown ---
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at Util.testClient.<GetForecastResultAsync>d__7.MoveNext() in d:\test\Util\testClient.cs:line 135
[05/26/2017 21:28:01 > 6e349c: ERR ] --- End of stack trace from previous location where exception was thrown ---
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at AutoAggregation.Functions.<>c__DisplayClass18_0.<ProcessResultDownloadMessage>b__0(Object workItem) in d:\test\AutoAggregation\Functions.cs:line 198
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.ThreadPoolWorkQueue.Dispatch()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Maria Ines Parnisari
  • 14,229
  • 7
  • 73
  • 112

2 Answers2

1

Might you be using the free Hosting Plan tier? This (https://tomssl.com/2016/12/20/how-to-get-azure-webjobs-to-run-indefinitely-for-free/) blog describes precicely the same issue and a workaround. For professional usage I would recommend upping the hosting plan

TLDR: The app pool under a free plan can run for a maximum of 20 minutes.

Henry Been
  • 315
  • 2
  • 10
1

I've increased timeout of HttpClient as:

_httpClient = new HttpClient();
_httpClient.Timeout=Timeout.InfiniteTimeSpan;

previously it was set to

_httpClient.Timeout=new TimeSpan(0, 20, 0);
slugster
  • 47,434
  • 13
  • 92
  • 138