You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CloudRequestEngine - change blocking httpClient.SendAsync(request).Result to Send(request).Result to not trigger Azure complaining about mixing async and sync code
#153
Open
justadreamer opened this issue
Dec 6, 2024
· 0 comments
· May be fixed by #158
We’ve detected that threads are mixing synchronous code with asynchronous code
Azure App Service has identified that 35 threads may be mixing synchronous code with asynchronous code. Application code is calling Task. Result and is synchronously waiting on the Task object, which can lead to deadlocks in the process.
The function calling Task.Result is FiftyOne.Pipeline.CloudRequestEngine.FlowElements.CloudRequestEngine.SendRequestAsync(System.Net.Http.HttpRequestMessage), but the entire thread's call stack should be reviewed to identify the blocking pattern. Please review the call stack closely and make sure that your code is using the C# await keyword.
HelperMethodFrame_1OBJ
System.Threading.ManualResetEventSlim.Wait
System.Threading.Tasks.Task.SpinThenBlockingWait
System.Threading.Tasks.Task.InternalWaitCore
System.Threading.Tasks.Task`1[[System.__Canon System.Private.CoreLib]].GetResultCore
FiftyOne.Pipeline.CloudRequestEngine.FlowElements.CloudRequestEngine.SendRequestAsync
FiftyOne.Pipeline.CloudRequestEngine.FlowElements.CloudRequestEngine.AddCommonHeadersAndSend
FiftyOne.Pipeline.CloudRequestEngine.FlowElements.CloudRequestEngine.ProcessEngine
FiftyOne.Pipeline.Engines.FlowElements.AspectEngineBase`2[[System.__Canon System.Private.CoreLib][System.__Canon System.Private.CoreLib]].ProcessWithCache
FiftyOne.Pipeline.Core.FlowElements.FlowElementBase`2[[System.__Canon System.Private.CoreLib][System.__Canon System.Private.CoreLib]].Process
FiftyOne.Pipeline.Core.FlowElements.Pipeline.Process
FiftyOne.Pipeline.Web.Services.PipelineResultService.Process
FiftyOne.Pipeline.Web.FiftyOneMiddleware+d__21.MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[FiftyOne.Pipeline.Web.FiftyOneMiddleware+d__21 FiftyOne.Pipeline.Web]]
FiftyOne.Pipeline.Web.FiftyOneMiddleware.Invoke
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware+d__5.MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware+d__5 Microsoft.AspNetCore.Localization]]
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke
Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware+d__7.MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware+d__7 Joonasw.AspNetCore.SecurityHeaders]]
Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware.Invoke
Microsoft.AspNetCore.Rewrite.RewriteMiddleware.Invoke
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke
Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware+d__4.MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware+d__4 Microsoft.AspNetCore.ResponseCompression]]
Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore
Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware+d__3.MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware+d__3 Microsoft.AspNetCore.Diagnostics]]
Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke
Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1+d__2[[System.__Canon System.Private.CoreLib]].MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1+d__2[[System.__Canon System.Private.CoreLib]] Microsoft.AspNetCore.Server.IIS]]
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1[[System.__Canon System.Private.CoreLib]].ProcessRequestAsync
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext+d__183.MoveNext
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext+d__183 Microsoft.AspNetCore.Server.IIS]]
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.HandleRequest
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.Execute
System.Threading.ThreadPoolWorkQueue.Dispatch
System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart
DebuggerU2MCatchHandlerFrame
App Service resource details
Subscription ID: fd5627cd-0955-421b-8ed0-ff309bfc4ca0
Subscription name:51Degrees.mobi Limited(Converted to EA)
Resource group name: 51dWebsiteApp
App name: 51d-website-westus
Date: November 16, 2024
Cause
The cause seems to be for us using SendAsync(request).Result - i.e. it's an async call returning a task, but we request the result of the task and essentially block on it converting it to a synchronous call.
Objective
The call is meant to be synchronous anyway, so let's use Send(request) instead of SendAsync in CloudRequestEngine.
The text was updated successfully, but these errors were encountered:
Background
Azure has sent us this message at least once:
We’ve detected that threads are mixing synchronous code with asynchronous code
Azure App Service has identified that 35 threads may be mixing synchronous code with asynchronous code. Application code is calling Task. Result and is synchronously waiting on the Task object, which can lead to deadlocks in the process.
App Service resource details
Subscription ID: fd5627cd-0955-421b-8ed0-ff309bfc4ca0
Subscription name:51Degrees.mobi Limited(Converted to EA)
Resource group name: 51dWebsiteApp
App name: 51d-website-westus
Date: November 16, 2024
Cause
The cause seems to be for us using
SendAsync(request).Result
- i.e. it's an async call returning a task, but we request the result of the task and essentially block on it converting it to a synchronous call.Objective
The call is meant to be synchronous anyway, so let's use Send(request) instead of SendAsync in CloudRequestEngine.
The text was updated successfully, but these errors were encountered: