Describe the bug
When thin client mode is enabled (AZURE_COSMOS_THIN_CLIENT_ENABLED=true), per-operation ExcludeRegions on ItemRequestOptions is ignored. All requests route to the first available thin client endpoint (typically the first write region) regardless of the excluded regions list.
Without thin client enabled, ExcludeRegions works correctly — each operation routes to the expected region.
To reproduce
Multi-writer account with 3 write regions (East US 2, West Central US, South Central US). Three CreateItemAsync calls, each excluding 2 regions to pin to a specific target region.
Environment.SetEnvironmentVariable("AZURE_COSMOS_THIN_CLIENT_ENABLED", "true");
using var client = new CosmosClient(endpoint, key, new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway,
ApplicationPreferredRegions = new List<string> { "East US 2", "West Central US", "South Central US" }
});
// Pin to West Central US by excluding the other two
var opts = new ItemRequestOptions
{
ExcludeRegions = new List<string> { "East US 2", "South Central US" }
};
var resp = await container.CreateItemAsync(item, pk, opts);
// Diagnostics show request went to eastus2:10250, NOT westcentralus:10250
Expected: Request routes to westcentralus.documents.azure.com:10250
Actual: Request routes to eastus2.documents.azure.com:10250
Root cause analysis
RequestInvokerHandler.SendAsync() (line ~125-146) branches for thin client operations and calls endpointManager.ResolveThinClientEndpoint(request) instead of ResolveServiceEndpoint(request).
LocationCache.ResolveThinClientEndpoint() (line ~933-949) selects from precomputed ThinClientWriteEndpoints/ThinClientReadEndpoints using index-based selection. It does not check request.RequestContext.ExcludeRegions.
The ExcludeRegions filtering only exists in the normal gateway path: LocationCache.ResolveServiceEndpoint() → GetApplicableEndpoints() (line ~416-448).
Suggested fix
ResolveThinClientEndpoint() should filter ThinClientWriteEndpoints/ThinClientReadEndpoints by request.RequestContext.ExcludeRegions before selecting the endpoint, mirroring the logic in GetApplicableEndpoints().
Environment
- SDK: Microsoft.Azure.Cosmos 3.58.0
- OS: Windows
- .NET: 10.0
Describe the bug
When thin client mode is enabled (
AZURE_COSMOS_THIN_CLIENT_ENABLED=true), per-operationExcludeRegionsonItemRequestOptionsis ignored. All requests route to the first available thin client endpoint (typically the first write region) regardless of the excluded regions list.Without thin client enabled,
ExcludeRegionsworks correctly — each operation routes to the expected region.To reproduce
Multi-writer account with 3 write regions (East US 2, West Central US, South Central US). Three
CreateItemAsynccalls, each excluding 2 regions to pin to a specific target region.Expected: Request routes to
westcentralus.documents.azure.com:10250Actual: Request routes to
eastus2.documents.azure.com:10250Root cause analysis
RequestInvokerHandler.SendAsync()(line ~125-146) branches for thin client operations and callsendpointManager.ResolveThinClientEndpoint(request)instead ofResolveServiceEndpoint(request).LocationCache.ResolveThinClientEndpoint()(line ~933-949) selects from precomputedThinClientWriteEndpoints/ThinClientReadEndpointsusing index-based selection. It does not checkrequest.RequestContext.ExcludeRegions.The
ExcludeRegionsfiltering only exists in the normal gateway path:LocationCache.ResolveServiceEndpoint()→GetApplicableEndpoints()(line ~416-448).Suggested fix
ResolveThinClientEndpoint()should filterThinClientWriteEndpoints/ThinClientReadEndpointsbyrequest.RequestContext.ExcludeRegionsbefore selecting the endpoint, mirroring the logic inGetApplicableEndpoints().Environment