Skip to content

Commit bf137c2

Browse files
authored
Prevent AsyncBearerTokenCredentialPolicy deadlock (Azure#11591)
1 parent ff8e5f5 commit bf137c2

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

sdk/core/azure-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Bug fixes
77

8+
- Fixed deadlocks in AsyncBearerTokenCredentialPolicy #11543
89
- Fix AttributeException in StreamDownloadGenerator #11462
910

1011
### Features

sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See LICENSE.txt in the project root for
44
# license information.
55
# -------------------------------------------------------------------------
6-
import threading
6+
import asyncio
77

88
from azure.core.pipeline import PipelineRequest
99
from azure.core.pipeline.policies import SansIOHTTPPolicy
@@ -21,7 +21,7 @@ class AsyncBearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOH
2121

2222
def __init__(self, credential, *scopes, **kwargs):
2323
super().__init__(credential, *scopes, **kwargs)
24-
self._lock = threading.Lock()
24+
self._lock = asyncio.Lock()
2525

2626
async def on_request(self, request: PipelineRequest):
2727
"""Adds a bearer token Authorization header to request and sends request to next policy.
@@ -32,7 +32,7 @@ async def on_request(self, request: PipelineRequest):
3232
"""
3333
self._enforce_https(request)
3434

35-
with self._lock:
35+
async with self._lock:
3636
if self._need_new_token:
3737
self._token = await self._credential.get_token(*self._scopes) # type: ignore
3838
self._update_headers(request.http_request.headers, self._token.token)

0 commit comments

Comments
 (0)