Unexpected timeout exception
Given this source code
builder.Services.AddHealthChecks()
.AddAzureCosmosDB(optionsFactory: static (sp) =>
{
CosmosDbOptions cosmosConfig = sp.GetRequiredService<IOptions<CosmosDbOptions>>().Value;
return new AzureCosmosDbHealthCheckOptions
{
DatabaseId = cosmosConfig.DatabaseName,
ContainerIds = [Constants.ConversationContainerName]
};
}, tags: ["Database"], timeout: TimeSpan.FromSeconds(2))
It works most of the time, but sometimes I find exception like this in the log, why?
I think it's weird I get a timeout exception, while Cosmos replied 200 OK in the expected time.
Environment:
- .NET 8 version
- AspNetCore.HealthChecks.CosmosDb version 8.0.0
- Linux Azure App Service
Did you ever find out what the cause of this was? I'm experiencing similar exceptions
Nope 😢
Hey guys, whatever is configured to check the application health has a low timeout of 2s, if the application fails to respond in this time, the request will be cancelled, and the CancellationTokens will do what they're supposed to do and end up throwing OperationCancelledException like you're getting.