Skip to content

Commit

Permalink
GatewayAddressCache: Fixes Unobserved Exception During Background Add…
Browse files Browse the repository at this point in the history
…ress Refresh (#4039)

* Code changes to fix unobserved exception during background address refresh.

* Code changes to add exception handler in task.

* Code changes to fix null ref exception.

* Revert "Code changes to fix null ref exception."

This reverts commit 83f90d5.

* Revert "Code changes to add exception handler in task."

This reverts commit c49ed81.

* Code changes to address review comments.

* Revert "Code changes to address review comments."

This reverts commit d2b9f6b.
  • Loading branch information
kundadebdatta authored Aug 16, 2023
1 parent 946dd4a commit 48af69e
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,27 @@ public async Task<PartitionAddressInformation> TryGetAddressesAsync(
.ReplicaTransportAddressUris
.Any(x => x.ShouldRefreshHealthStatus()))
{
Task refreshAddressesInBackgroundTask = Task.Run(async () => await this.serverPartitionAddressCache.RefreshAsync(
key: partitionKeyRangeIdentity,
singleValueInitFunc: (currentCachedValue) => this.GetAddressesForRangeIdAsync(
request,
cachedAddresses: currentCachedValue,
Task refreshAddressesInBackgroundTask = Task.Run(async () =>
{
try
{
await this.serverPartitionAddressCache.RefreshAsync(
key: partitionKeyRangeIdentity,
singleValueInitFunc: (currentCachedValue) => this.GetAddressesForRangeIdAsync(
request,
cachedAddresses: currentCachedValue,
partitionKeyRangeIdentity.CollectionRid,
partitionKeyRangeIdentity.PartitionKeyRangeId,
forceRefresh: true));
}
catch (Exception ex)
{
DefaultTrace.TraceWarning("Failed to refresh addresses in the background for the collection rid: {0} with exception: {1}. '{2}'",
partitionKeyRangeIdentity.CollectionRid,
partitionKeyRangeIdentity.PartitionKeyRangeId,
forceRefresh: true)));
ex,
System.Diagnostics.Trace.CorrelationManager.ActivityId);
}
});
}

return addresses;
Expand Down

0 comments on commit 48af69e

Please sign in to comment.