Unclosed client session in azure.containerregistry.aio.ContainerRegistryClient.list_repository_names
- Package Name: azure-containerregistry==1.0.0b4, azure-core==1.16.0, azure-identity==1.6.0
- Operating System: OS X
- Python Version: Python 3.9.4
Describe the bug
Using azure.containerregistry.aio.ContainerRegistryClient.list_repository_names results in the following aiohttp warning:
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10b264ee0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x10b2e84c0>, 1.472941262)]']
connector: <aiohttp.connector.TCPConnector object at 0x10b3020a0>
To Reproduce Based on the sample from https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_delete_old_tags_async.py I do run the following:
import asyncio
import os
class ListOperations(object):
def __init__(self, account_url=None):
if account_url is None:
self.account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
else:
self.account_url = account_url
async def print_repository(self):
from azure.containerregistry.aio import (
ContainerRegistryClient,
)
from azure.identity.aio import AzureCliCredential
credential = AzureCliCredential()
client = ContainerRegistryClient(self.account_url, credential)
async with client:
async for repository in client.list_repository_names():
print(repository)
async def main():
sample = ListOperations()
await sample.print_repository()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Expected behavior There is no warning about unclosed sessions and connectors.
Thanks for reporting this! someone from our team will soon take a look
@bjoern-meier-by thanks for reporting this issue! I believe this issue is caused by the sessions not being closed on the credential as well. I modified your sample and this should close all connections:
import asyncio
import os
class ListOperations(object):
def __init__(self, account_url=None):
if account_url is None:
self.account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
else:
self.account_url = account_url
async def print_repository(self):
from azure.containerregistry.aio import (
ContainerRegistryClient,
)
from azure.identity.aio import AzureCliCredential
credential = AzureCliCredential()
async with credential:
client = ContainerRegistryClient(self.account_url, credential)
async with client:
async for repository in client.list_repository_names():
print(repository)
async def main():
sample = ListOperations()
await sample.print_repository()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
No this does not change it, running your adapted code still gives:
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10bdfe370>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x10bddb5e0>, 2.813222607)]']
connector: <aiohttp.connector.TCPConnector object at 0x10bdfe1f0>
@xiangyan99 could you investigate the root cause first, thanks!
@lmazuel We were assigning the issue at same time. :)
@bjoern-meier-by Thanks for reporting the issue. It is fixed and the fix will be available in next release (mid-Aug).
Hi @bjoern-meier-by. 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.
Hi @bjoern-meier-by, 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.