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

CrossRegionHedging: Fixes NullReference Exception Bug #4869

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ internal override async Task<ResponseMessage> ExecuteAvailabilityStrategyAsync(
request,
hedgeRegions.ElementAt(requestNumber),
cancellationToken,
cancellationTokenSource);
cancellationTokenSource, trace);
dibahlfi marked this conversation as resolved.
Show resolved Hide resolved
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved

requestTasks.Add(primaryRequest);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ private async Task<HedgingResponse> CloneAndSendAsync(
clonedRequest,
region,
cancellationToken,
cancellationTokenSource);
cancellationTokenSource, trace);
dibahlfi marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -271,7 +271,7 @@ private async Task<HedgingResponse> RequestSenderAndResultCheckAsync(
RequestMessage request,
string hedgedRegion,
CancellationToken cancellationToken,
CancellationTokenSource cancellationTokenSource)
CancellationTokenSource cancellationTokenSource, ITrace trace)
dibahlfi marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
Expand All @@ -288,9 +288,9 @@ private async Task<HedgingResponse> RequestSenderAndResultCheckAsync(

return new HedgingResponse(false, response, hedgedRegion);
}
catch (OperationCanceledException) when (cancellationTokenSource.IsCancellationRequested)
catch (OperationCanceledException oce ) when (cancellationTokenSource.IsCancellationRequested)
dibahlfi marked this conversation as resolved.
Show resolved Hide resolved
{
return new HedgingResponse(false, null, hedgedRegion);
throw new CosmosOperationCanceledException(oce, trace);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,60 @@ public async Task AvailabilityStrategyStepTests(string operation, string condito
}
}

[TestMethod]
[TestCategory("MultiRegion")]
[ExpectedException(typeof(CosmosOperationCanceledException))]
public async Task AvailabilityStrategyWithCancellationTokenThrowsExceptionTest()
{
FaultInjectionRule responseDelay = new FaultInjectionRuleBuilder(
id: "responseDely",
condition:
new FaultInjectionConditionBuilder()
.WithRegion("Central US")
.WithOperationType(FaultInjectionOperationType.ReadItem)
.Build(),
result:
FaultInjectionResultBuilder.GetResultBuilder(FaultInjectionServerErrorType.ResponseDelay)
.WithDelay(TimeSpan.FromMilliseconds(6000))
.Build())
.WithDuration(TimeSpan.FromMinutes(90))
.WithHitLimit(2)
.Build();

List<FaultInjectionRule> rules = new List<FaultInjectionRule>() { responseDelay };
FaultInjector faultInjector = new FaultInjector(rules);

responseDelay.Disable();

CosmosClientOptions clientOptions = new CosmosClientOptions()
{
ConnectionMode = ConnectionMode.Direct,
ApplicationPreferredRegions = new List<string>() { "Central US", "North Central US" },
AvailabilityStrategy = AvailabilityStrategy.CrossRegionHedgingStrategy(
threshold: TimeSpan.FromMilliseconds(300),
thresholdStep: null),
Serializer = this.cosmosSystemTextJsonSerializer
};

using (CosmosClient faultInjectionClient = new CosmosClient(
connectionString: this.connectionString,
clientOptions: faultInjector.GetFaultInjectionClientOptions(clientOptions)))
{
CancellationTokenSource cts = new CancellationTokenSource();
cts.Cancel();

Database database = faultInjectionClient.GetDatabase(CosmosAvailabilityStrategyTests.dbName);
Container container = database.GetContainer(CosmosAvailabilityStrategyTests.containerName);

ItemResponse<AvailabilityStrategyTestObject> ir = await container.ReadItemAsync<AvailabilityStrategyTestObject>(
dibahlfi marked this conversation as resolved.
Show resolved Hide resolved
kirankumarkolli marked this conversation as resolved.
Show resolved Hide resolved
"testId",
new PartitionKey("pk"), cancellationToken: cts.Token
);

}

}

private static async Task HandleChangesAsync(
ChangeFeedProcessorContext context,
IReadOnlyCollection<AvailabilityStrategyTestObject> changes,
Expand Down