Description
Library name and version
Azure.Search.Documents 11.5.0
Describe the bug
Hi guys!
In our anaylsis we have tried to execute the SearchClient.Index(batch) method from non-controller code (e.g. GlobalAsax.cs) and it succeeds
Executing the same method from anywhere within a controller method's codepath (including controller constructor, or the constructors of its base classes) fail (i.e. hang).
Using the fiddler, we can see that in both cases the HTTP request is successfully executed.
Based on our debugging results, the last method before hanging is HttpClientTransport.ProcessAsync.
After my investigation, I've identified that the problem is in the SearchClient.Transport property.
I've populated that property - Transport = new HttpClientTransport(new HttpClient(handler))
where handler is my new class with the following code:
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { return await base.SendAsync(request, cancellationToken); }
The issue is occurred only when I use 'await' operator. Running the send method synchronously (.GetAwaiter().GetResult();
) fixes the problem
Expected behavior
Azure.Search.Documents.SearchClient.Index(batch) should always return a result (or throw an exception)
Actual behavior
In some cases Azure.Search.Documents.SearchClient.Index(batch) method doesn't return a result, it appears to hang
Reproduction Steps
Create an ASP.NET WEB API project and call the following code in any controller's endpoint:
public class LoggingHandler : HttpClientHandler
{
public LoggingHandler() { }
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return await base.SendAsync(request, cancellationToken);
}
}
//GET api/values/int endpoint
public string Get(int id)
{
var ids = new List<int> { id };
var batch = IndexDocumentsBatch.Delete(ids.Select(x => new SubscriberAzureSearchable() { ID = x.ToString() }));
var handler = new LoggingHandler();
var indexClient = new SearchClient(new Uri("https://example.com"), "example", new AzureKeyCredential("example"), new SearchClientOptions()
{
Transport = new HttpClientTransport(new HttpClient(handler))
});
var result = indexClient.IndexDocuments(batch);
return result.ToString();
}
Environment
Project: ASP.NET WEB API
Platform: .NET Framework 4.7.2
IDE: Visual Studio 2022
Metadata
Metadata
Assignees
Labels
Type
Projects
Status