From 162c2423ca05ada36d22dc6d7a7c49c625ad5232 Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Wed, 5 Nov 2025 17:48:45 -0800 Subject: [PATCH] fix: added fix for async handle not closing correctly --- adlfs/utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/adlfs/utils.py b/adlfs/utils.py index d4a00a98..615815d9 100644 --- a/adlfs/utils.py +++ b/adlfs/utils.py @@ -1,3 +1,4 @@ +import inspect from typing import Optional try: @@ -81,5 +82,14 @@ async def close_credential(file_obj): Implements asynchronous closure of credentials for AzureBlobFile objects """ - if not isinstance(file_obj.credential, (type(None), str)): - await file_obj.credential.close() + credential = getattr(file_obj, "credential", None) + if credential is None or isinstance(credential, str): + return + + close_method = getattr(credential, "close", None) + if not callable(close_method): + return + + close_result = close_method() + if inspect.isawaitable(close_result): + await close_result