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

[BUG]:CosmosNullReferenceException when hedging enabled and client called with cancelled cancellation token #4737

Open
anderuso opened this issue Sep 30, 2024 · 0 comments
Assignees
Labels
customer-reported Issue created by a customer needs-investigation

Comments

@anderuso
Copy link

Describe the bug
CosmosNullReferenceException is thrown when cosmosdb client hedging enabled in the client 3.44.0P and ReadItemAsync() is called with cancelled cancellation token

To Reproduce
Create a cosmos client instance with Hedging enabled and call the client's ReadItemAsync() method with an already canceled cancellation token (when AvailabilityStrategy option is not set, CosmosOperationCanceledException is thrown properly).

CosmosClientOptions options = new CosmosClientOptions
{
    ConnectionMode = ConnectionMode.Direct,
    ApplicationPreferredRegions = new[] { "Central US", "France Central" },
    AvailabilityStrategy = AvailabilityStrategy.CrossRegionHedgingStrategy(TimeSpan.FromMilliseconds(50), null)
};
CosmosClient client = new CosmosClient("https://account:443/", new DefaultAzureCredential(), options);
CancellationTokenSource cts = new CancellationTokenSource();
cts.Cancel();
await client.GetContainer("db", "container").ReadItemAsync<ItemType>("a", new PartitionKey("b"), cancellationToken: cts.Token);

Expected behavior
CosmosOperationCanceledException is thrown

Actual behavior
CosmosNullReferenceException Exception is thrown

Environment summary
SDK Version: cosmos-netstandard-sdk/3.44.0P
OS Version (e.g. Windows, Linux, MacOSX): X64|Microsoft Windows 10.0.20348|.NET 8.0.8

Additional context
Actual stack trace:
---> (Inner) System.AggregateException
---> (Inner #0) Microsoft.Azure.Cosmos.CosmosNullReferenceException: Object reference not set to an instance of an object.{"Summary":{},"name":"ReadItemAsync","start datetime":"2024-09-27T08:21:27.877Z","duration in milliseconds":0.6168,"data":{"Client Configuration":{"Client Created Time Utc":"2024-09-26T07:35:42.1814932Z","MachineId":"vmId","VM Region":"centralus","NumberOfClientsCreated":4,"NumberOfActiveClients":4,"ConnectionMode":"Direct","User Agent":"cosmos-netstandard-sdk/3.44.0P|1|X64|Microsoft Windows 10.0.20348|.NET 8.0.8|L|","ConnectionConfig":{"gw":"(cps:50, urto:6, p:False, httpf: False)","rntbd":"(cto: 2, icto: -1, mrpc: 30, mcpe: 65535, erd: True, pr: PrivatePortPool)","other":"(ed:False, be:False)"},"ConsistencyConfig":"(consistency: NotSet, prgns:[Central US, South Central US], apprgn: )","ProcessorCount":4},"DistributedTraceId":"e33cf7078803921b45b15859607c23d4"},"children":[{"name":"Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler","duration in milliseconds":0.4678,"children":[{"name":"Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler","duration in milliseconds":0.1713,"children":[{"name":"Microsoft.Azure.Cosmos.Handlers.TelemetryHandler","duration in milliseconds":0.1331,"children":[{"name":"Microsoft.Azure.Cosmos.Handlers.RetryHandler","duration in milliseconds":0.0923}]}]},{"name":"Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler","duration in milliseconds":0.1242,"children":[{"name":"Microsoft.Azure.Cosmos.Handlers.TelemetryHandler","duration in milliseconds":0.0865,"children":[{"name":"Microsoft.Azure.Cosmos.Handlers.RetryHandler","duration in milliseconds":0.0506}]}]}]}]}
---> (Inner) System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ProcessMessage(ResponseMessage responseMessage, Func`2 createResponse)
at await Microsoft.Azure.Cosmos.ContainerCore.ReadItemAsync(?)
at await Microsoft.Azure.Cosmos.ClientContextCore.RunWithDiagnosticsHelperAsync(?)
<---
at await Microsoft.Azure.Cosmos.ClientContextCore.RunWithDiagnosticsHelperAsync(?)
at await Microsoft.Azure.Cosmos.ClientContextCore.OperationHelperWithRootTraceAsync(?)
at our code calling the client's ReadItemAsync()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issue created by a customer needs-investigation
Projects
None yet
Development

No branches or pull requests

2 participants