Share via

DocumentAnalysisClient.AnalyzeDocument intermittently hangs

Matthew Callahan 20 Reputation points
2023-05-02T02:32:57.83+00:00

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?

Azure Document Intelligence in Foundry Tools

1 answer

Sort by: Most helpful
  1. Lachlan Bambach 85 Reputation points
    2023-05-03T23:22:42.1666667+00:00

    Microsoft have confirmed the issue in the Australia East region and suggested moving the FR resource to another international region whilst the product team work on a fix. No ETA given at this stage.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.