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

Unclosed client session in azure.containerregistry.aio.ContainerRegistryClient.list_repository_names

Open bjoern-meier-by opened this issue 5 years ago • 8 comments

  • 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.

bjoern-meier-by avatar Jul 30 '21 08:07 bjoern-meier-by

Thanks for reporting this! someone from our team will soon take a look

rakshith91 avatar Jul 30 '21 19:07 rakshith91

@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())

seankane-msft avatar Jul 30 '21 20:07 seankane-msft

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>

bjoern-meier-by avatar Aug 02 '21 05:08 bjoern-meier-by

@xiangyan99 could you investigate the root cause first, thanks!

lmazuel avatar Aug 02 '21 23:08 lmazuel

@lmazuel We were assigning the issue at same time. :)

xiangyan99 avatar Aug 02 '21 23:08 xiangyan99

@bjoern-meier-by Thanks for reporting the issue. It is fixed and the fix will be available in next release (mid-Aug).

xiangyan99 avatar Aug 03 '21 18:08 xiangyan99

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.

ghost avatar Aug 03 '21 18:08 ghost

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.

ghost avatar Aug 10 '21 22:08 ghost