Это происходит только при большой нагрузке, поэтому я не могу привести простой пример. Это для системного теста, поэтому я пытаюсь избежать ожидания и вместо этого я создаю 2000 запросов, а затем опрашиваю, когда ответы завершены.
Код проблемного c:
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.<---