A task was canceled - what does this mean?
Asked Answered
S

2

8

I'm using the Azure Search .Net SDK.

I'm calling a synchronous (NOT ASYNC) function like this:

var searchResults = searchIndexClient.Documents.Search<T>(searchText, searchParameters);

It usually works. I'm not using any async functions, but somehow the error I just got looks like an async error:

System.Threading.Tasks.TaskCanceledException: A task was canceled.

CancellationToken: IsCanceleationRequested=false

Task: Id = 556, Status = Canceled, Method = "{null}", Result = "{Not yet computed}"

StackTrace:

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.Search.DocumentsOperations.<DoContinueSearchWithHttpMessagesAsync>d__153.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.Search.DocumentsOperationsExtensions.<SearchAsync>d__151.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.Azure.Search.DocumentsOperationsExtensions.Search[T](IDocumentsOperations operations, String searchText, SearchParameters searchParameters, SearchRequestOptions searchRequestOptions) at MyApp.AzureSearch.AzureSearchService.PerformSearch[T](String searchText, SearchParameters searchParameters) in c:\Projects\MyAppServer\src\MyApp.AzureSearch\AzureSearchService.cs:line 359 at MyApp.AzureSearch.AzureSearchService.Search[T](String searchText, List1 searchFields, SearchMode searchMode, List1 select, Nullable1 skip, Nullable1 top, String filter, Boolean includeTotalResultCount, List1 orderBy) in c:\Projects\MyAppServer\src\MyApp.AzureSearch\AzureSearchService.cs:line 262 at MyApp.AzureSearch.AzureSearchService.SearchEmails(Guid userId, String origin, String searchText, Nullable1 skip, Nullable1 top, Boolean includeTotalResultCount, Boolean includeHtmlBody, Boolean orderByProcessedAscending, String interactionStatus) in c:\Projects\MyAppServer\src\MyApp.AzureSearch\AzureSearchService.cs:line 167 at MyApp.Domain.MyAppMessages.Command.MyAppMessagesAllNoticedUpdater.Handle(VisitorSession userSession, NoticeAllMyAppMessages processCommand) in c:\Projects\MyAppServer\src\MyApp.Domain\MyAppMessages\Command\MyAppMessagesAllNoticedUpdater.cs:line 30

Superinduce answered 7/11, 2016 at 7:23 Comment(1)
i had same issue and drafted my answer hereBerget
R
5

Most likely, the client timeout expired before the search has completed. Are you seeing this error when you submit a particularly complex query? If needed, you can look at the search performance in your service using search traffic analytics.

The reason you're seeing an "asynchronous" exception is that the synchronous version of the API is just a wrapper over asynchronous primitives.

Repeat answered 7/11, 2016 at 7:57 Comment(2)
Thanks, I figured it was just wrapping an async function. It wasn't a complex query at all, and very little data in the query as well. I didn't expect the .net SDK to throw an error unless something was misconfigured in the query. Is there a list of all possible errors that can be thrown by the .net sdk that I should handle?Superinduce
The main exceptions that can be thrown are: CloudException, IndexBatchException (for indexing only), ValidationException, and of course OperationCanceledException (or its subclass TaskCanceledException you're dealing with here). But since C# is not a checked exception language, you might see other exceptions as well (such as ArgumentException).Repeat
I
0

Pass CancellationToken=null and make the code as async methods.

Illdisposed answered 28/8, 2020 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.