Skip to content

Commit 7c76ff7

Browse files
Copilotcgillum
andcommitted
Add try/finally blocks to ensure session cleanup on close failures
Co-authored-by: cgillum <2704139+cgillum@users.noreply.github.com>
1 parent 5601f19 commit 7c76ff7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

azure/durable_functions/models/utils/http_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ async def _handle_request_error():
5454
global _client_session
5555
async with _session_lock:
5656
if _client_session is not None and not _client_session.closed:
57-
await _client_session.close()
58-
_client_session = None
57+
try:
58+
await _client_session.close()
59+
finally:
60+
_client_session = None
5961

6062

6163
async def _close_session() -> None:
@@ -67,8 +69,10 @@ async def _close_session() -> None:
6769

6870
async with _session_lock:
6971
if _client_session is not None and not _client_session.closed:
70-
await _client_session.close()
71-
_client_session = None
72+
try:
73+
await _client_session.close()
74+
finally:
75+
_client_session = None
7276

7377

7478
async def post_async_request(url: str,

0 commit comments

Comments
 (0)