Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure-Identity] How to atexit DefaultAzureCredential? #8972

Closed
NetGH opened this issue Dec 4, 2019 · 3 comments
Closed

[Azure-Identity] How to atexit DefaultAzureCredential? #8972

NetGH opened this issue Dec 4, 2019 · 3 comments
Assignees
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization.

Comments

@NetGH
Copy link

NetGH commented Dec 4, 2019

How to gracefully dispose DefaultAzureCredential?

import asyncio
from azure.identity.aio import DefaultAzureCredential

async def test():
    credential = DefaultAzureCredential()
    await credential.get_token('https://management.core.windows.net/.default')
    
asyncio.run( test() )

Warning:

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x00000253F1779688>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x00000253F1788438>, 114171.5)]']
connector: <aiohttp.connector.TCPConnector object at 0x00000253F1779748>
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x00000253F1754888>

@chlowell
Copy link
Member

chlowell commented Dec 4, 2019

Thanks for reporting this! I just opened an issue about it as well (#8990) before seeing this 😆. Currently there's no graceful way to close the session through the credential's public API. I'll fix it internally so credentials properly close their own sessions.

@chlowell chlowell added Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. and removed triage labels Dec 4, 2019
@chlowell chlowell self-assigned this Dec 4, 2019
@chlowell chlowell added this to the [2020] January milestone Dec 4, 2019
@chlowell
Copy link
Member

I found no acceptable way for credentials to close their own transport sessions, so in the next release async credentials will be async context managers with close methods (implemented by #9090). That creates two ways to close a credential's session in your example:

  1. Call close
import asyncio
from azure.identity.aio import DefaultAzureCredential

async def test():
    credential = DefaultAzureCredential()
    await credential.get_token('https://management.core.windows.net/.default')
    await credential.close()
    
asyncio.run( test() )
  1. Use async with
import asyncio
from azure.identity.aio import DefaultAzureCredential

async def test():
    credential = DefaultAzureCredential()
    async with credential:
        await credential.get_token('https://management.core.windows.net/.default')
    
asyncio.run( test() )

@chlowell
Copy link
Member

The methods I described above are available now in azure-identity 1.2.0. I'll close this issue for now; thank you again for opening it. Please reopen this, or open another issue, if you have further trouble.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization.
Projects
None yet
Development

No branches or pull requests

2 participants