Monday, April 20, 2020

Azure Cosmos DB Emulator error : No connection could be made because the target machine actively refused it

We have some integration tests as well as end to end scenario tests which rely on Azure Cosmos DB Emulator for verifying Data layer contracts and the data layer storage manager APIs.

This helps us ensure that our all our storage layer APIs will work as expected in real Azure Cosmos environment. Yes I hear you, and I also leverage MOQ framework for our unit testing and mock testing, but this gives an added level of safety and peace of mind, that I am not mocking the storage, and the storage layer/managers will work as expected as is working in Cosmos DB emulator

Sometimes you may hit the following error :

Message:  

System.ArgumentException :Error while trying to get the containerSystem.ArgumentException: Error while trying to get the databaseSystem.Net.Http.HttpRequestException: No connection could be made because the target machine actively refused it.

     ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.

       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)

       --- End of inner exception stack trace ---

       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)

       at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)

       at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)

       at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)

       at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)

       at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

       at Microsoft.Azure.Cosmos.DocumentClient.HttpRequestMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

       at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)

       at Microsoft.Azure.Cosmos.GatewayAccountReader.GetDatabaseAccountAsync(Uri serviceEndpoint)

       at Microsoft.Azure.Cosmos.Routing.GlobalEndpointManager.GetDatabaseAccountFromAnyLocationsAsync(Uri defaultEndpoint, IList`1 locations, Func`2 getDatabaseAccountFn)

       at Microsoft.Azure.Cosmos.GatewayAccountReader.InitializeReaderAsync()

       at Microsoft.Azure.Cosmos.CosmosAccountServiceConfiguration.InitializeAsync()

       at Microsoft.Azure.Cosmos.DocumentClient.InitializeGatewayConfigurationReaderAsync()

       at Microsoft.Azure.Cosmos.DocumentClient.GetInitializationTaskAsync(IStoreClientFactory storeClientFactory)

       at Microsoft.Azure.Cosmos.DocumentClient.EnsureValidClientAsync()

       at Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler.EnsureValidClientAsync(RequestMessage request)

       at Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)

       at Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler.SendAsync(Uri resourceUri, ResourceType resourceType, OperationType operationType, RequestOptions requestOptions, ContainerInternal cosmosContainerCore, Nullable`1 partitionKey, Stream streamPayload, Action`1 requestEnricher, CosmosDiagnosticsContext diagnosticsContext, CancellationToken cancellationToken)

       at Microsoft.Azure.Cosmos.CosmosClient.<>c__DisplayClass30_0.<<CreateDatabaseIfNotExistsAsync>b__0>d.MoveNext()

    --- End of stack trace from previous location where exception was thrown ---



This means that your local Azure cosmos DB emulator is not running. You can verify it by browsing to https://localhost:8081/_explorer/index.html. If you dont see any thing it means the service / daemon is stopped. Simply locate Cosmso DB emulator on your machine and start it

Section 80C TMT 2023(PA) – Standard Deduction amounting to a maximum of Rs 8670 under IT rule

With the recently concluded Tax filing season (which if I may draw parallel to the Christmas holiday season enjoyed by one and all), Indians...