【发布时间】:2020-08-10 07:34:18
【问题描述】:
这只发生在重负载下,所以我不能举一个简单的例子。这是一个系统测试,所以我试图避免等待,而是创建 2,000 个请求,然后轮询响应何时完成。
有问题的代码是:
Task<HttpResponseMessage> response = responseStatus.Item1;
if (!response.IsCompleted)
continue;
HttpResponseMessage result = response.Result;
对 Result 的调用会引发以下情况:
System.AggregateException: One or more errors occurred.
StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at SystemTests.V2.LoadTests.Test1000Requests() in C:\git\Jenova\restfulengine\SystemTests.V2\LoadTests.cs:line 121
INNER EXCEPTION: System.Threading.Tasks.TaskCanceledException: A task was canceled.
StackTrace: System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at SystemTests.V2.LoadTests.Test1000Requests() in C:\git\Jenova\restfulengine\SystemTests.V2\LoadTests.cs:line 121
---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
2020-04-26 13:36:06,370 [MSTestAdapter Thread] WARN SystemTests.V2.LoadTests - v2/reports/19ea788d-ceb8-4a81-a974-f597494609dd failed (will retry)System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at SystemTests.V2.LoadTests.Test1000Requests() in C:\git\Jenova\restfulengine\SystemTests.V2\LoadTests.cs:line 121
---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
【问题讨论】:
标签: c# async-await httpresponsemessage