Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.61k stars 2.83k forks source link

Resource leak in Microsoft Azure Form Recognizer azure.ai.formrecognizer.aio.DocumentAnalysisClient unclosed aiohttp Client Session #37403

Closed abhijithautoai closed 1 month ago

abhijithautoai commented 1 month ago

While calling azure.ai.formrecognizer.aio.DocumentAnalysisClient for doing ocr for 200 pages using async event loop i am intermittently getting "Unclosed client session warnings". Some of the aiohttp sessions internally created in the client is not closed.

client initialisation code is : self.client = DocumentAnalysisClient(self.config_dict["FORM_RECOGNIZER_ENDPOINT"], credential=DefaultAzureCredential(), api_version = self.config_dict["FORM_RECOGNIZER_API_VERSION"] session=session, ,session_owner = False ) I am passing an aiohttp Session to the client and i am closed the session using async with. the client is also wrapped around async with. I tried without passing the session created by me, the resource leak error still persists.

async with aiohttp.ClientSession() as session: print_active_sessions() async with await get_ocr_reader(session=session) as reader: result = await analyze_files( model_id, page_image_list) return result this is the consumer code.

To Reproduce

  1. Using the client do ocr for 200 pages. Sleep for 3 min Again do ocr for 200 pages. Sleep for 3 min while doing it the third time one will get the resource leak warning.

Ideally all sessions created by DocumentAnalysisClient should be closed by it. If user is passing a session, then the client should use that session and should not create any sessions for itself.

aiohttp version is 3.10.5

xiangyan99 commented 1 month ago

Thanks for the feedback, we’ll investigate asap.

YalinLi0312 commented 1 month ago

Hi @abhijithautoai , the unclosed session is from credential, you should manually close it or using with keyword. Please follow the examples in this doc: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/README.md#async-credentials

github-actions[bot] commented 1 month ago

Hi @abhijithautoai. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] commented 1 month ago

Hi @abhijithautoai. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] commented 1 month ago

Hi @abhijithautoai. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] commented 1 month ago

Hi @abhijithautoai, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.