[BUG] Azure Search: Deadlock searching for documents with DocumentsOperationsExtensions.Search()
See original GitHub issueDescribe the bug We’ve upgraded our existing Azure Search implementation to use the newest 9.0.0 version of .NET SDK, resolved all breaking changes, but the synchronous search methods seem to deadlock.
Stack Trace
mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout = -1, System.Threading.CancellationToken cancellationToken)
mscorlib.dll!System.Threading.Tasks.Task.SpinThenBlockingWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
mscorlib.dll!System.Threading.Tasks.Task.InternalWait(int millisecondsTimeout = -1, System.Threading.CancellationToken cancellationToken)
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task = Id = 2351, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}")
Microsoft.Azure.Search.Data.dll!Microsoft.Azure.Search.DocumentsOperationsExtensions.Search(Microsoft.Azure.Search.IDocumentsOperations operations, string searchText, Microsoft.Azure.Search.Models.SearchParameters searchParameters, Microsoft.Azure.Search.Models.SearchRequestOptions searchRequestOptions)
CMSApp.dll!CMSWebParts_DancingGoat_Samples_DancingGoatSmartSearchAzure.Page_Load(object sender = CMSAbstractWebPart("SampleDancingGoat_SmartSearchAzure"), System.EventArgs e = {System.EventArgs})
....
Code Snippet
result = searchIndexClient.Documents.Search(searchString, searchParams);
It seems the following code in DocumentsOperationsExtensions.cs is missing a ConfigureAwait(false) before synchronously waiting for the result.
public static DocumentSearchResult<Document> Search(
this IDocumentsOperations operations,
string searchText,
SearchParameters searchParameters = null,
SearchRequestOptions searchRequestOptions = default(SearchRequestOptions))
{
return operations.SearchAsync(searchText, searchParameters, searchRequestOptions).GetAwaiter().GetResult();
}
Similar methods possibly with the same issue:
Microsoft.Azure.Search.DocumentsOperationsExtensions.Search(...)
Microsoft.Azure.Search.DocumentsOperationsExtensions.Search\<T\>(...)
Microsoft.Azure.Search.DocumentsOperationsExtensions.Count(...)
Microsoft.Azure.Search.DocumentsOperationsExtensions.Autocomplete(...)
etc.
Expected behavior No deadlock. Synchronous search is possible.
Setup (please complete the following information):
- Azure Search .NET SDK version 9
Additional context I can see the JSON response in Fiddler, but the method doesn’t return anything.
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [ x ] Bug Description Added
- [ x ] Repro Steps Added
- [ x ] Setup information Added
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Version 9.0.1, which includes this fix, is now available on NuGet.
@tomillie Thanks for confirming. I have a PR out for the fix and I hope to be able to push it to NuGet today.