问题描述
.net Azure搜索SDK升级到版本9后,我无法搜索.通话挂断了:
After upgrading the .net Azure Search SDK to version 9, I am unable to search. The call just hangs on:
azureSearchIndexClient.Documents.Search(query, parameters);
我没有收到任何错误,一切都在5.0.3上进行,我仍然可以在版本9中创建,填充和删除索引.没有任何响应,我几乎没事做...
I don't receive an error, everything was working on 5.0.3, I can still create, populate, and delete indexes in version 9. Without any response, I have little to go on...
推荐答案
这是SDK 9.0.0版中的一个错误,在此处进行了跟踪: https://github.com/Azure/azure-sdk-for-net/issues/6254 此后已在9.0版中修复.1,现在可以在NuGet上下载.截至撰写本文时,版本8.0.0-preview仍受此错误影响.
This is a bug in version 9.0.0 of the SDK, tracked here: https://github.com/Azure/azure-sdk-for-net/issues/6254 It has since been fixed in version 9.0.1, now available for download on NuGet. Version 8.0.0-preview is still affected by this bug as of the time of this writing.
原因是缺少对ConfigureAwait(false)
的调用,在ASP.NET经典应用程序的上下文中调用SDK时会导致死锁.
The cause is a missing call to ConfigureAwait(false)
, which results in deadlock when calling the SDK in the context of an ASP.NET classic app.
该错误仅影响用于发送POST请求的代码路径.因此,将UseHttpGetForQueries
设置为true
是有效的解决方法.但是,仅在解决方案可用之前,才应将其用作临时解决方案,尤其是在您的应用程序发送可能不适合URL查询字符串的非常大的查询时.
The bug only affects the code path used for sending POST requests. That’s why setting UseHttpGetForQueries
to true
is an effective workaround. However, this should only be used as a temporary solution until the fix is available, especially if your application sends very large queries that might not fit on the URL query string.
还请注意,仅当阻塞从异步方法返回的Task时才发生死锁. SDK的同步方法在内部执行此操作.建议在ASP.NET中进行实践,以使您的控制器方法以及它们调用的可能潜在执行I/O的所有方法异步,包括Azure Search SDK的方法.这样可以防止OS线程被阻塞,从而极大地提高了应用程序的可伸缩性.它还避免了由于缺少对ConfigureAwait(false)
的调用而导致潜在死锁的问题.
Also note that the deadlock only occurs when blocking on a Task returned from an async method. The synchronous methods of the SDK do this internally. It is recommended practice in ASP.NET to make your controller methods async, as well as all methods that they call that can potentially do I/O, including the methods of the Azure Search SDK. This prevents OS threads from blocking, which greatly increases the scalability of your app. It also avoids issues with potential deadlock due to missing calls to ConfigureAwait(false)
.
这篇关于将Azure Search SDK从v.5.0.3升级到v.9.搜索电话挂断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!