Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentClient: Fixes ObjectDisposedException during Background Refresh by adding Cancellation Token #3278

Merged
merged 9 commits into from
Jun 21, 2022
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
//SessionContainer.
internal ISessionContainer sessionContainer;

private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

private AsyncLazy<QueryPartitionProvider> queryPartitionProvider;

Expand Down Expand Up @@ -1205,7 +1205,7 @@ public void Dispose()
return;
}

if (this.cancellationTokenSource != null && !this.cancellationTokenSource.IsCancellationRequested)
if (!this.cancellationTokenSource.IsCancellationRequested)
{
this.cancellationTokenSource.Cancel();
imanvt marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/GatewayAccountReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class GatewayAccountReader
private readonly AuthorizationTokenProvider cosmosAuthorization;
private readonly CosmosHttpClient httpClient;
private readonly Uri serviceEndpoint;
private CancellationToken cancellationToken;
private readonly CancellationToken cancellationToken;

// Backlog: Auth abstractions are spilling through. 4 arguments for this CTOR are result of it.
public GatewayAccountReader(Uri serviceEndpoint,
Expand Down Expand Up @@ -71,7 +71,7 @@ await this.cosmosAuthorization.AddAuthorizationHeaderAsync(
{
trace.AddDatum("Client Side Request Stats", stats);
throw CosmosExceptionFactory.CreateRequestTimeoutException(
message: ex.Data?["Message"].ToString(),
message: ex.Message,
headers: new Headers()
{
ActivityId = System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ void TraceHandler(string message)
using CosmosClient cosmos = new(ConnectionString);
}

string assertMsg = "";
string assertMsg = string.Empty;
imanvt marked this conversation as resolved.
Show resolved Hide resolved

foreach (string s in errors)
{
assertMsg += s + "\n";
assertMsg += s + Environment.NewLine;
}

Assert.AreEqual(0, errors.Count, $"\nErrors found in trace:\n{assertMsg}");
Assert.AreEqual(0, errors.Count, $"{Environment.NewLine}Errors found in trace:{Environment.NewLine}{assertMsg}");
}

private class TestTraceListener : TraceListener
Expand Down