System.OperationCanceLedException:取消操作-Azure webapi

发布于 2025-02-07 19:14:41 字数 1594 浏览 2 评论 0原文

我已经经历了我正在努力的网站突然开始投掷操作CanceLedException。它似乎始于5月25日,没有对网站的已知更改。

有人经历过同样的事情吗?最近的Azure可能会有任何变化吗?任何浏览器的新版本都可以具有这种效果吗(例如,Google Chrome似乎有一些版本约为24-25/5)?

看来仅影响WebApi-endpoints。尚未听到最终用户的任何抱怨,所以我不知道它有多认真,但它以下面的方式显示在日志中。 共同点是,它似乎只会影响Webapi-endpoint(我们以/api/*为我们)

*2022-06-14T19:00:29,Error,***************,*******,******,0,9760,45,"System.Object : Unhandled Exception at /api/search/autocomplete
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Net.Http.HttpContentExtensions.<ReadAsAsyncCore>d__17`1.MoveNext()

...omitted some of the stack traces, but it ends with this...

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                                                
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)                                                
   at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()                                                
   at System.Web.HttpApplication.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0()                                             
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)                                               
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)",*                                               

I've experienced that the site I'm working on suddenly started to throw OperationalCanceledException. It seems to been started approx 25 May without no known changes to the site.

Does anyone have experienced the same thing? Could it be any changes in Azure lately that could have that effect? could A new version of any browser have that effect (for example Google Chrome seems to have some releases approx 24-25/5)?

It seems only affects webapi-endpoints. Have not heard any complaints from end-users, so I don't know how serious it is, but it shows up in logs as below.
The things in common are that it only seems to affect webapi-endpoints (starting with /api/* for us)

*2022-06-14T19:00:29,Error,***************,*******,******,0,9760,45,"System.Object : Unhandled Exception at /api/search/autocomplete
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Net.Http.HttpContentExtensions.<ReadAsAsyncCore>d__17`1.MoveNext()

...omitted some of the stack traces, but it ends with this...

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()                                                
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)                                                
   at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()                                                
   at System.Web.HttpApplication.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0()                                             
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)                                               
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)",*                                               

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2025-02-14 19:14:41

挖掘此问题后,我发现由于API呼叫没有响应,可能会发生例外。

system.Object:未经处理的异常,at/api/search/autocomplete system.operationCanceLedException:该操作已取消。

当API呼叫暂停时,问题发生。为避免此问题,您可以更改 httpclient.timeout

HttpClient httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromMinutes(10);

确保检查您的代码是否需要很长时间才能完成。您必须等待完成该任务。使用 httpclient.timeout 等待完成任务。

您可以使用 类中的API中的类别以了解确切问题何时发生/何时发生。

参考

After dig into this issue, I found the exception may occur because of API call doesn't respond.

System.Object : Unhandled Exception at /api/search/autocomplete System.OperationCanceledException: The operation was canceled.

The issue happens when the API call gets timeout. To avoid this issue, you can change your HttpClient.Timeout.

HttpClient httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromMinutes(10);

Make sure to check your code if any of your process taking long to complete. You have to wait for completing that task. Use HttpClient.Timeout for wait to complete the task.

You can use the OperationCanceledException class in your API to know when/where the exact issue happens.

Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文