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
149 stars 45 forks source link

Cosmos SDK experiences timeouts if mapped ports in docker-compose file differ #50

Open ben-graffle opened 2 years ago

ben-graffle commented 2 years ago

Receiving 408 timeouts with the cosmos C# SDK with specific port mapping configurations in a docker-compose file

docker compose that works

cosmos:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
    container_name: cosmos
    ports:
      - 8081:8081
      - 10251:10251
      - 10252:10252
      - 10253:10253
      - 10254:10254
    expose:
      - "8081"
      - "10251-10255"
    environment:
      - AZURE_COSMOS_EMULATOR_PARTITION_COUNT=6
      - AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false
      - AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=${LOCALIPADDRESS}

docker compose that does not work

cosmos:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
    container_name: cosmos
    expose:
      - "8081"
      - "10251-10255"
    ports:
      - 8082:8081
      - 10252:10251
      - 10253:10252
      - 10254:10253
      - 10255:10254
    environment:
      - AZURE_COSMOS_EMULATOR_PARTITION_COUNT=6
      - AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false
      - AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=${LOCALIPADDRESS}

Function call that throws exception

var httpMessageHandler = new HttpClientHandler()
{
    ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};

CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
{
    HttpClientFactory = () => new HttpClient(httpMessageHandler),
    ConnectionMode = ConnectionMode.Gateway,
    Serializer = new CosmosJsonNetCustomSerializer(),
    RequestTimeout = TimeSpan.FromMinutes(3)
};

using CosmosClient client = new CosmosClient(cosmosEndpoint, COMSOS_KEY, cosmosClientOptions);

var db = await client.CreateDatabaseIfNotExistsAsync("DbName", 4000, null, CancellationToken.None);

The first docker-compose yaml works and the second does not. Receiving the following error

Unhandled exception. Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: RequestTimeout (408); Substatus: 0; ActivityId: 2f24681b-db18-44aa-afc8-e12ba02d8930; Reason: (GatewayStoreClient Request Timeout. Start Time UTC:03/29/2022 22:28:56; Total Duration:36015.4719 Ms; Request Timeout 20000 Ms; Http Client Timeout:180000 Ms; Activity id: 2f24681b-db18-44aa-afc8-e12ba02d8930;);

The reason I am looking to map the ports differently is i need to have two cosmos emulator docker containers running simultaneously.

Any assistance/insight would be greatly appreciated.

AMI3GOLtd commented 2 years ago

I'm facing the same issue. I hope you don't mind but I've posted it on Stack Overflow to widen the audience https://stackoverflow.com/questions/71751494

gopisrikanthkosuru commented 1 month ago

It would be nice Microsoft people look into the permanent solution