WindowsAzure.Storage.StorageException when used, wait for an asynchronous call in webjob

I use a webjob on an azure website to work with a heavy process that consumes a lot of memory. This process makes many back-end web calls, so it was designed as async. I want the webjob to work with only one instance request. I set Queues.BatchSize = 1 parameter to disable parallel in webjob. However, when I use await to call the async method, the next message is still selected immediately from the queue, since waiting does not really block the current thread, which is good for the UI application, but not for my case.

So, I tried to use wait to block the current thread until the whole internal process is complete. However, upon completion of the process, an exception was thrown. there seems to be a problem with the webjob to delete the queue after waiting.

I attached a simplified test code and exceptions. Any ideas?

Thank you for help!

ProcessWebJob namespace {

public class Functions { public static void ProcessQueueMessage([QueueTrigger("testQueue")] string message, TextWriter log) { try { testAsync ts = new testAsync(); var task = Task.Run(async () => { await ts.test(); }); task.Wait(); }catch(Exception e){ Trace.TraceInformation("error on processing the queue message" + e.InnerException); } } } public class testAsync { public async Task<int> test() { await Task.Delay(10000); //10 seconds delay return 1; } } 

}

[07/10/2015 17:57:14> 278796: ERR] Unhandled exception: Microsoft.WindowsAzure.Storage.StorageException: The remote server responded with an error: (404) Not found. ---> System.Net.WebException: The remote server responded with an error: (404) Not found. [10/07/2015 17:57:14> 278796: ERR] on Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException [T] (HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusBd, cmt, RetStatusBode, cmt, RetStatusCode actualStatusCd, cmt, RetStatusCd, 1 cmd, Exception ex) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.<DeleteBlobImpl>b__29(RESTCommand actualStatusBode 1 cmd, Exception ex) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.<DeleteBlobImpl>b__29(RESTCommand 1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx) [10/07 / 2015 17:57:14> 278796: ERR] at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse [T] (IAsyncResult getResponseResult) [10/07/2015 17:57:14> 278796: ERR] - - End of internal check of the exception stack --- [10/07/2015 17:57:14> 278796: ERR] in Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync [T] (result of IAsyncResult) [10/07 / 2015 17:57:14> 278796: ERR] at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions. <> c__DisplayClass4.b__3 (IAsyncResult ar) [10/07/2015 17:57:14> 278796: ERR] --- The end of the stack trace from the previous place where the exception was thrown --- [10/07/2015 17: 57:14> 278796: ERR] in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (task task) [10/07/2015 17:57:14> 278796: ERR] in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebug Task tasks) [10/07/2015 17:57:14> 278796: ERR] at Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueWriter 1.<DeleteAsync>d__6.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Loggers.CompositeFunctionInstanceLogger.<DeleteLogFunctionStartedAsync>d__e.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__1.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueTriggerExecutor.<ExecuteAsync>d__0.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter 1.<DeleteAsync>d__6.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Loggers.CompositeFunctionInstanceLogger.<DeleteLogFunctionStartedAsync>d__e.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__1.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueTriggerExecutor.<ExecuteAsync>d__0.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter 1.<DeleteAsync>d__6.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Loggers.CompositeFunctionInstanceLogger.<DeleteLogFunctionStartedAsync>d__e.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__1.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueTriggerExecutor.<ExecuteAsync>d__0.MoveNext() [10/07/2015 17:57:14 > 278796: ERR ] --- End of stack trace from previous location where exception was thrown --- [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [10/07/2015 17:57:14 > 278796: ERR ] at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult () [10/07/2015 17:57:14> 278796: ERR] on Microsoft. Azure.WebJobs.Host.Queues.Listeners.QueueListener.d__11.MoveNext () [10/07/2015 17:57:14> 278796: ERR] --- The end of the stack trace from the previous place where it was selected exclusively statement --- [10/07/2015 17:57:14> 278796: ERR] in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [10/07/2015 17:57:14> 278796: ERR] in System .Threading.ExecutionContext.RunInternal (ExecutionContext executeContext, ContextCallback callback, object state, Boolean preserveSyncCtx) [10/07/2015 17:57:14> 278796: ERR] in System.Threading.ExecutionContext.Run (ExecutionContext executeContext ContextCallback, object state, Boolean preserveSyncCtx) [10/07/2015 17:57:14> 278796: ERR] in System.Threading.ExecutionContext.Run (Execution Context execution Context, ContextCallback callback, Object state) [10/07/2015 17 : 57: 14> 278796: ERR] in System.Threading.ThreadHelper.ThreadStart () [07/07/2015 17:57:14> 278796: SYS ERR] Failed to complete due to exit code -5 32462766

+5
source share

Source: https://habr.com/ru/post/1233191/


All Articles