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.ConfiguredTaskAwaitable
1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.Search.DocumentsOperations.<DoContinueSearchWithHttpMessagesAsync>d__15
3.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__15
1.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, List
1 searchFields, SearchMode searchMode, List1 select, Nullable
1 skip, Nullable1 top, String filter, Boolean includeTotalResultCount, List
1 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, Nullable
1 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
For canceling, we use CancellationTokenSource object.
You can "abort" a task by running it on a thread you control and aborting that thread. This causes the task to complete in a faulted state with a ThreadAbortException . You can control thread creation with a custom task scheduler, as described in this answer.
To cancel, call tcs. SetResult(Nothing). This will fire your Task.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With