Skip to content

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

Closed

Description

  • azure-ai-formrecognizer
  • 3.3.3
  • Ubuntu 22
  • Python 3.9.2

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Document Intelligencecustomer-reportedIssues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions