question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Cosmos client connecting to wrong port when using emulator

See original GitHub issue

Describe the bug I have the cosmos emulator running on a container using port 9999 instead of 8081. I’m using the C# client to connect to it, but it just hangs indefinitly. Looking at the output window, I see that it’s trying to connect to port 8081 regardless of what my endpoint is.

Expected behavior It should connect to the correct port.

Actual behavior (include Exception or Stack Trace) It’s connecting to the wrong port.

DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://localhost:9999/ with ConnectionMode: Gateway, connection Protocol: Https, and consistency level: null
DocDBTrace Information: 0 : Telemetry Disabled.
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Globalization.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Users\goenning\Desktop\CosmosLocalSDK\bin\Debug\net5.0\Microsoft.Azure.Cosmos.Core.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Numerics.Vectors.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Collections.Immutable.dll'. Symbols loaded.
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Runtime.CompilerServices.Unsafe.dll'. Symbols loaded.
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Security.Cryptography.Encoding.dll'. Symbols loaded.
DocDBTrace Information: 0 : SystemUsageMonitor started
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Threading.Tasks.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.IO.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Dynamic.Runtime.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Runtime.Serialization.Formatters.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Runtime.Numerics.dll'. Symbols loaded.
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Reflection.Emit.ILGeneration.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Reflection.Primitives.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.Reflection.Emit.Lightweight.dll'. 
'CosmosLocalSDK.exe' (CoreCLR: clrhost): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.21.0.2:8081/) ReadEndpoints = (https://172.21.0.2:8081/)
DocDBTrace Information: 0 : GlobalEndpointManager: StartLocationBackgroundRefreshWithTimer() refreshing locations
Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Sockets.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Http.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Sockets.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Http.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Sockets.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Http.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in Microsoft.Azure.Cosmos.Client.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
DocDBTrace Warning: 0 : ClientRetryPolicy: Gateway HttpRequestException Endpoint not reachable. Failed Location: https://172.21.0.2:8081/; ResourceAddress: dbs/TEST
DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.21.0.2:8081/ unavailable for read
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.21.0.2:8081/) ReadEndpoints = (https://172.21.0.2:8081/)
DocDBTrace Information: 0 : Endpoint https://172.21.0.2:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 10/11/2021 09:42:39
DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.21.0.2:8081/ unavailable for Write
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.21.0.2:8081/) ReadEndpoints = (https://172.21.0.2:8081/)
DocDBTrace Information: 0 : Endpoint https://172.21.0.2:8081/ unavailable for Write added/updated to unavailableEndpoints with timestamp 10/11/2021 09:42:39
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.21.0.2:8081/) ReadEndpoints = (https://172.21.0.2:8081/)

To Reproduce

  1. Start a cosmos emulator on linux container ( https://docs.microsoft.com/en-us/azure/cosmos-db/linux-emulator?tabs=ssl-netstd21 ) using port 9999 instead of 8081
  2. Write a simple C# script that connects to it.
  3. It’ll just hang indefinitly, look at output window.

Environment:

  • Cosmos Emulator Image sha256:42dd3146bf324c4c5fe59b23352b65c19b3780795c28da97f524e86cc32aa5ed
  • Microsoft.Azure.Cosmos = 3.21.0
  • Windows 10
  • Visual Studio Enterprise 2019

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
goenningcommented, Oct 11, 2021

Thanks for the info, I reached out to the emulator team and got this reply in case someone is looking for it.

We don't fully document how this can be done today but there are some options that allows you to pass other options to start the emulator.
For instance you can pass in the environment variable "AZURE_COSMOS_EMULATOR_ARGS" via Docker's "-e" option. This could take a list of emulator command line arguments as if you invoke the executable yourself (Command-line and PowerShell reference for Azure Cosmos DB Emulator | Microsoft Docs).

Another option is to override the default container's startup command, (see Docker options) and provide your own script/custom command that will replace it. In Windows Docker container this is a PowerShell script that you have access to. The custom logic will have to take the current command and add to it:
$startEmulatorCmd = "Start-CosmosDbEmulator -AllowNetworkAccess -NoFirewall -NoUI -Key $Key $startEmulatorOptions"

I hope the above steps help.

This is how it looks now:

version: '2'
services:
  cosmosdb:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
    container_name: cosmosdb
    restart: always
    ports:
      - 9999:9999 
      - 10251:10251 
      - 10252:10252 
      - 10253:10253 
      - 10254:10254
    environment:
      AZURE_COSMOS_EMULATOR_ARGS: /Port=9999
0reactions
ealsurcommented, Oct 11, 2021

Thanks for sharing the docker steps for future users.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot issues when using the Azure Cosmos DB ...
Learn how to troubleshot service unavailable, certificate, encryption, and versioning issues when using the Azure Cosmos DB Emulator.
Read more >
Adding Cosmos DB Emulator connection with alternate ...
In the "Connect to Cosmos DB" dialog, change the port in the AccountEndpoint value (or change anything about the AccountEndpoint value that ...
Read more >
CosmosDB emulator can't start since port is already in use
The CosmosDbEmulator comes with a PowerShell module, which you can use to control it. To get started using the module run the following...
Read more >
Setting Up Azure Cosmos DB Emulator for Development
While Azure Cosmos DB service can be an important storage system for your applications, sometimes using it during development can be ...
Read more >
CosmosDB in a Containerized Dev Environment
In this article we cover: How to set up a containerized dev environment for CosmosDB development. How to configure the new CosmosDB emulator...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found