Azure / azure-cosmos-db-emulator-docker

This repo serves as hub for managing issues, gathering feedback, and having discussions regarding the Cosmos DB Emulator Docker.
https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Ccsharp&pivots=api-nosql
MIT License
150 stars 45 forks source link

Read/Write endpoints unreachable #98

Open Makciek opened 3 months ago

Makciek commented 3 months ago

Describe the bug After pulling the newest image my integration tests started breaking with some very strange errors. So I tried to create the simplest repro but I found out that even just the basic scenario copied from docs(https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Ccsharp&pivots=api-nosql#import-the-emulators-tlsssl-certificate) doesn't work.

To Reproduce Follow https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Ccsharp&pivots=api-nosql#import-the-emulators-tlsssl-certificate

When running:

using CosmosClient cosmosClient = new(
    accountEndpoint: "https://localhost:8081/",
    authKeyOrResourceToken: "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
);
Database database = await cosmosClient.CreateDatabaseIfNotExistsAsync(
    id: "cosmicworks",
    throughput: 400
);

Application(.net 8, Microsoft.Azure.Cosmos:3.40.0) hangs, the output windows print the following:

... DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.5:8081/) ReadEndpoints = (https://172.17.0.5:8081/) DocDBTrace Information: 0 : GlobalEndpointManager: StartLocationBackgroundRefreshWithTimer() refreshing locations DocDBTrace Information: 0 : Creating RNTBD TransportClient with options Rntbd.TransportClient.Options OpenTimeout: 00:00:05 RequestTimeout: 00:00:06 TimerPoolResolution: 00:00:01 MaxChannels: 65535 PartitionCount: 1 MaxRequestsPerChannel: 30 ReceiveHangDetectionTime: 00:01:05 SendHangDetectionTime: 00:00:10 IdleTimeout: -00:00:01 UserAgent: cosmos-netstandard-sdk/3.40.0|1|X64|Microsoft Windows 10.0.22631|.NET 8.0.5|N| Suffix: CertificateHostNameOverride: LocalRegionTimeout: 00:00:05 EnableChannelMultiplexing: False MaxConcurrentOpeningConnectionCount: 5 Use_RecyclableMemoryStream: False Use_CustomDnsResolution: False IsDistributedTracingEnabled: False DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1 DocDBTrace Information: 0 : Creating RNTBD TransportClient with options Rntbd.TransportClient.Options OpenTimeout: 00:00:05 RequestTimeout: 00:00:06 TimerPoolResolution: 00:00:01 MaxChannels: 65535 PartitionCount: 1 MaxRequestsPerChannel: 1 ReceiveHangDetectionTime: 00:01:05 SendHangDetectionTime: 00:00:10 IdleTimeout: -00:00:01 UserAgent: cosmos-netstandard-sdk/3.40.0|1|X64|Microsoft Windows 10.0.22631|.NET 8.0.5|N| Suffix: CertificateHostNameOverride: LocalRegionTimeout: 00:00:05 EnableChannelMultiplexing: False MaxConcurrentOpeningConnectionCount: 5 Use_RecyclableMemoryStream: False Use_CustomDnsResolution: False IsDistributedTracingEnabled: False DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1 DocDBTrace Information: 0 : Resolving Master service address, forceMasterRefresh: False, currentMaster: The thread '.NET TP Worker' (2488) has exited with code 0 (0x0). DocDBTrace Warning: 0 : ClientRetryPolicy: Gateway HttpRequestException Endpoint not reachable. Failed Location: https://172.17.0.5:8081/; ResourceAddress: dbs/cosmicworks DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.5:8081/ unavailable for read DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.5:8081/) ReadEndpoints = (https://172.17.0.5:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.5:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 05/22/2024 14:53:57 DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.5:8081/ unavailable for Write DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.5:8081/) ReadEndpoints = (https://172.17.0.5:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.5:8081/ unavailable for Write added/updated to unavailableEndpoints with timestamp 05/22/2024 14:53:57 DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.5:8081/) ReadEndpoints = (https://172.17.0.5:8081/) DocDBTrace Information: 0 : Resolving Master service address, forceMasterRefresh: False, currentMaster: DocDBTrace Warning: 0 : ClientRetryPolicy: Gateway HttpRequestException Endpoint not reachable. Failed Location: https://172.17.0.5:8081/; ResourceAddress: dbs/cosmicworks ... and so on...

Expected behavior Doesn't hang

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Docker Images Used:

**Arguments && Environment variables to start Docker: docker run --publish 8081:8081 --publish 10250-10255:10250-10255 --interactive --tty mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest

Docker Environment

Makciek commented 3 months ago

regarding the original issue - it looks like the newest version returns the malformed response when there are no records as a result of the query - sorry for not creating a separate issue but I can't create a simple repro for it because of above image

Makciek commented 3 months ago

the same code works when running on the non-docker emulator

Makciek commented 3 months ago

looks like using --env AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1 helps with the issue of hangning

Makciek commented 3 months ago

and here's the simplest repro for my 'original' issue: image

Makciek commented 3 months ago

using

var query = container
    .GetItemLinqQueryable<Model>
    (
        linqSerializerOptions: new CosmosLinqSerializerOptions()
        {
            PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
        },
        requestOptions: new QueryRequestOptions()
        {
            PartitionKey = new PartitionKey(Guid.NewGuid().ToString())
        }
    )
    .Where(x => true);

instead fixes the issue

Makciek commented 3 months ago

@sajeetharan hey, my workaround is just a workaround - the issue is still there the new docker emulator behaves differently from the actual cosmos db/windows emulator