Closed arvind-sarvam closed 2 days ago
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jalauzon-msft @vincenttran-msft.
Thanks for reaching out.
DefaultAzureCredential manages sessions for you.
Could you share the reason why you create a session instance when you create DefaultAzureCredential?
Hi @arvind-sarvam. 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.
Hi, we saw some connection leak inside the library in the session created per Request. It happens sort of randomly. For many requests, there is no problem, suddenly we see a ClientSession that is not closed. This also gave a lot of : "Unclosed client session" errors.
Due to the above, I chose to pass a session to DefaultAzureCredential. Another added benefit from this is performance gain for requests since this is long lived in nature.
On Wed, Aug 21, 2024, 9:33 PM github-actions[bot] @.***> wrote:
Hi @arvind-sarvam https://github.com/arvind-sarvam. 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.
— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-sdk-for-python/issues/36959#issuecomment-2302448392, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJD4O6CZ3EHVT26MWVHGLALZSS24NAVCNFSM6AAAAABM2KCZY6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBSGQ2DQMZZGI . You are receiving this because you were mentioned.Message ID: @.***>
Thanks for the information.
Do you want to manage the lifecycle of the session object or not?
If you want to manage the lifetime of the session instance, you need to add session_owner=False when you create the client.
self.credential = DefaultAzureCredential(session=aiohttp.ClientSession(), session_owner=False)
and you need to close the session by yourself.
Hi @arvind-sarvam. 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.
Hi @arvind-sarvam, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
Describe the bug I'm using container client to perform operations on blob storage. The container client is initialized as:
On application shutdown, I invoke
shutdown()
that closes the client & credential:However, even after
shutdown()
when I print objects (usinggc.get_objects()
), I can see that there is aClientSession
object still held bySharedTokenCacheCredential
. I confirmed it withobjgraph
.On debugging, I found that the session stored inside
self._client_kwargs["session"]
is not getting closed hereTo Reproduce Run this script:
Expected behavior I expect all relevant client sessions to be closed on invoking
shutdown()
Screenshots Added in-line above
Additional context When I add these lines to this
I can see that this closes the connection properly, and GC count shows 0 which is expected. I'm not a 100% sure if this is the right fix, please check and let me know.