Home > Blockchain >  Azure Cosmos DB : 503 Service Unavaiable
Azure Cosmos DB : 503 Service Unavaiable

Time:10-22

While connecting from my code out side company network, Cosmos DB connection works just fine. but from within the network. it throws 503 Service unavailable issue.

I wanted to confirm if my speculation is correct. so I can ask IT specific help for connecting to Cosmos database and make some exceptions in firewall ?

CodePudding user response:

Based on the comments:

System.Exception: 'Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: ServiceUnavailable (503); Substatus: 0;
ActivityId: ; 
Reason: (The request failed because the client was unable to establish connections to 4 endpoints across 1 regions. Please check for client resource starvation issues and verify connectivity between client and server.

Normally, if you take that exception and store or view the ToString(), it will show you more information. But from the message itself, it means the client tried to connect to all known endpoints available and failed.

This normally means there is either something on the network blocking your request or the machine executing this code is completely overloaded (CPU at 100% or port exhaustion) and cannot process any request.

If this is consistently failing for all operations, check that your network has the correct port range open:

Port ranges for each connection mode

By default, the SDK works in Direct mode, so check that ports in the 10000 through 20000 range are open and available. If you have private endpoint enabled, the range is 0 to 65535.

As @GauravMantri mentioned, you can change to Gateway mode also if the network is restricted:

string connectionString = "<your-account-connection-string>";
CosmosClient client = new CosmosClient(connectionString,
new CosmosClientOptions
{
    ConnectionMode = ConnectionMode.Gateway 
});
  • Related