Skip to content

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

Open

Description

@ben-graffle

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.

Activity

  1. AMI3GOLtd commented on Apr 5, 2022

    @AMI3GOLtd

    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

  2. gopisrikanthkosuru commented on Jul 9, 2024

    @gopisrikanthkosuru

    It would be nice Microsoft people look into the permanent solution

  3. removed this from the vNext GA milestone on Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions