I've been using Form Recognizer SDK (.NET 4.8) for years without issues - but recently (in the past few days) calls to AnalyzeDocument are sometimes hanging.
Here is an example of the code:
using (var ms = new MemoryStream(fileData, 0, fileData.Length))
{
var options = new AnalyzeDocumentOptions() { Locale = "en-US" };
var operation = _formRecognizerClient.AnalyzeDocument(WaitUntil.Completed, "prebuilt-invoice", ms, options).WaitForCompletion();
var analyseResult = operation.Value; //It never reaches this line
}
I'd have a console app running this in multiple threads - it would work fine for a while and then just stop - all threads would be hung/stuck at the line waiting for completion.
I then tried changing the approach to this:
using (var ms = new MemoryStream(fileData, 0, fileData.Length))
{
var options = new AnalyzeDocumentOptions() { Locale = "en-US" };
var operation = _formRecognizerClient.AnalyzeDocument(WaitUntil.Started, "prebuilt-invoice", ms, options);
var stopWatch = new Stopwatch();
stopWatch.Start();
while (!operation.HasValue)
{
Logger.Instance.Debug("Azure Form Recognizer: Processing...");
if (stopWatch.Elapsed > TimeSpan.FromMinutes(2))
{
throw new Exception("Azure Form Recognizer: timeout");
}
Thread.Sleep(5000);
operation.UpdateStatus();
}
stopWatch.Stop();
var analyseResult = operation.Value;
}
With this code it eventually hits the 'throw new Exception' line after 2mins. The code around this function will automatically retry and the next time this is called it will work. It will then continue to work for a while again and then start hanging (or timing out in the 2nd code example) - rinse and repeat.
This is in Australia East region. .NET Framework 4.8. Azure.AI.FormRecognizer SDK v4.0.0
Any ideas why this would be happening all of a sudden?