Skip to content

Commit 6ec5379

Browse files
authored
[Cosmos] Bugfix for race condition on async lock (#34579)
* Update _global_endpoint_manager_async.py * Update CHANGELOG.md * skip waiting for network request since we're updating regardless * Update CHANGELOG.md
1 parent 930d75e commit 6ec5379

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Breaking Changes
88

99
#### Bugs Fixed
10+
* Fixed bug with async lock not properly releasing on async global endpoint manager. see [PR 34579](https://github.com/Azure/azure-sdk-for-python/pull/34579).
1011

1112
#### Other Changes
1213
* Marked `computed_properties` keyword as provisional, un-marked `continuation_token_limit` as provisional. See [PR 34207](https://github.com/Azure/azure-sdk-for-python/pull/34207).

sdk/cosmos/azure-cosmos/azure/cosmos/aio/_global_endpoint_manager_async.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,29 @@ async def force_refresh(self, database_account):
8383
await self.refresh_endpoint_list(database_account)
8484

8585
async def refresh_endpoint_list(self, database_account, **kwargs):
86-
async with self.refresh_lock:
87-
# if refresh is not needed or refresh is already taking place, return
88-
if not self.refresh_needed:
89-
return
90-
try:
91-
await self._refresh_endpoint_list_private(database_account, **kwargs)
92-
except Exception as e:
93-
raise e
86+
if self.refresh_needed:
87+
async with self.refresh_lock:
88+
# if refresh is not needed or refresh is already taking place, return
89+
if not self.refresh_needed:
90+
return
91+
try:
92+
await self._refresh_endpoint_list_private(database_account, **kwargs)
93+
except Exception as e:
94+
raise e
9495

9596
async def _refresh_endpoint_list_private(self, database_account=None, **kwargs):
97+
self.refresh_needed = False
9698
if database_account:
9799
self.location_cache.perform_on_database_account_read(database_account)
98-
self.refresh_needed = False
99-
100-
if (
101-
self.location_cache.should_refresh_endpoints()
102-
and self.location_cache.current_time_millis() - self.last_refresh_time > self.refresh_time_interval_in_ms
103-
):
104-
if not database_account:
100+
else:
101+
if (
102+
self.location_cache.should_refresh_endpoints()
103+
and
104+
self.location_cache.current_time_millis() - self.last_refresh_time > self.refresh_time_interval_in_ms
105+
):
105106
database_account = await self._GetDatabaseAccount(**kwargs)
106107
self.location_cache.perform_on_database_account_read(database_account)
107108
self.last_refresh_time = self.location_cache.current_time_millis()
108-
self.refresh_needed = False
109109

110110
async def _GetDatabaseAccount(self, **kwargs):
111111
"""Gets the database account.

0 commit comments

Comments
 (0)