azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

FormRecognizer behavior when service starts throttling

Open dev-td opened this issue 3 years ago • 6 comments

  • Package Name: azure-ai-formrecognizer
  • Package Version: 3.2.0
  • Operating System: Windows / Linux
  • Python Version: 3.8 / 3.9

Describe the bug When service form recognizer starts to throttle it raises error I/O Operation on closed file.

To Reproduce Please check code snippet below. `

async def analyse_document_async(document: io.BytesIO):
      endpoint, key = ...
  
      # instantiate client
      document_analysis_client = DocumentAnalysisClient(
          endpoint=endpoint, credential=AzureKeyCredential(key)
      )
  
      # generate analysis_args
      analysis_args = {"model_id": "prebuilt-invoice", "document": document}
  
      # non blocking async call
      async with document_analysis_client:
          # Suppose to raise HttpError 429 when service starts to throttle (during scale-out)
          # Instead raise I/O Operation on closed file...
          poller = await document_analysis_client.begin_analyze_document(**analysis_args)
          result = await poller.result()
  
  
      return result


async def orchestrate_async_function(documents: List[io.BytesIO]):
  
      tasks = [asyncio.create_task(analyse_document_async(doc)) for doc in documents]
      # concurrent call
      finished, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_EXCEPTION)
  
      return finished

`

Expected behavior Should raise HttpError 429

dev-td avatar Nov 05 '22 09:11 dev-td

Label prediction was below confidence level 0.6 for Model:ServiceLabels: 'Storage:0.12575616,Cognitive - Form Recognizer:0.12186136,Service Bus:0.104554616'

azure-sdk avatar Nov 05 '22 09:11 azure-sdk

Thanks for the feedback, we’ll investigate asap.

xiangyan99 avatar Nov 07 '22 17:11 xiangyan99

Thanks for reaching out @dev-td! If possible, could you please share the error message you're getting?

~~@vkurpad could you loop someone in from the service team to take a look?~~ [not a service issue]

catalinaperalta avatar Nov 09 '22 20:11 catalinaperalta

Hi @catalinaperalta , sure it's ValueError: I/O operation on closed file I can try to provide the error stack of that helps.

dev-td avatar Nov 09 '22 20:11 dev-td

@catalinaperalta possibly related: https://github.com/Azure/azure-sdk-for-python/issues/20040

kristapratico avatar Nov 09 '22 20:11 kristapratico

Ah I see, thanks for the info @dev-td and @kristapratico. Let me take a look

catalinaperalta avatar Nov 09 '22 20:11 catalinaperalta

Hi @dev-td, I wanted to follow up and let you know that we're still looking into a fix for this issue. In the meantime, if possible, could you share the error stack please?

catalinaperalta avatar Nov 16 '22 01:11 catalinaperalta

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

ghost avatar Nov 29 '22 02:11 ghost