Skip to content

CosmosDB emulator fails #10723

Open
Open

Description

@The3G

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

CosmosDB emulator fails to start
Aspire.Hosting.Dcp.dcp.start-apiserver.api-server.container-logstreamer.LogDescriptorSet[0]
Error disposing log descriptor {"ResourceName": {"name":"appcosmos-avndbgtb"}, "ResourceUID": "970a1dff-349b-4c04-998b-615cd95cc0ad", "error": "context deadline exceeded\ncontext deadline exceeded"}

Expected Behavior

CosmosDB emulator should start

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

No response

Anything else?

No response

Activity

  1. added
    area-integrations
    on Jul 29, 2025
  2. changed the title [-]CosmosDB fails[/-] on Jul 29, 2025
  3. davidfowl commented on Jul 29, 2025

    @davidfowl
    Collaborator

    Any more information? It doesn’t fail on my machine.

  4. davidfowl commented on Jul 29, 2025

    @davidfowl
    Collaborator
  5. karolz-ms commented on Jul 29, 2025

    @karolz-ms
    Contributor

    This error is most likely a red herring; a symptom not the cause. My bet is that the emulator container is not starting for some reason. The3G do you see any errors in the logs for the emulator in the Aspire dashboard? Can you check Docker/Podman logs for this container?

  6. The3G commented on Jul 29, 2025

    @The3G
    Author

    Karol Zadora-Przylecki (@karolz-ms) docker logs don't seem to show any errors; the container is starting if I run it via commandline outside of the aspire project (visualstudio) F5

  7. davidfowl commented on Jul 29, 2025

    @davidfowl
    Collaborator

    The3G There isn't enough details here to do an investigation. Can you record a video, and provide more information about versions, your project (maybe push a repo to github), what container runtime you are using, operating system etc. Without any of this we cant help with this problem.

  8. added
    needs-author-action
    azure-cosmosdb
    on Jul 29, 2025
  9. The3G commented on Jul 29, 2025

    @The3G
    Author

    David Fowler (@davidfowl) I'll do this tommorrow as it's 23hrs here in the UK;

    BTW, I've been using .NET 10 with nightly builds for aspire packages,
    but also see this using NET 9.0 and aspire 9.4.0 pacakges.

    Docker version 28.3.2, build 578ccf6

    Windows 11 Enterprise
    Version 24H2
    Installed on ‎18/‎07/‎2025
    OS build 26100.4652

  10. removed
    needs-author-action
    on Jul 29, 2025
  11. davidfowl commented on Jul 29, 2025

    @davidfowl
    Collaborator

    Record a video showing what happens in the dashboard and docker.

  12. The3G commented on Jul 30, 2025

    @The3G
    Author

    David Fowler (@davidfowl) Karol Zadora-Przylecki (@karolz-ms) I'm closing this issue as this seems not to be related to CosmosDB specifically and may be environment as I'm not seeing this on a different machine and I am seeing the same with other aspire projects from templates (without modification)

  13. karolz-ms commented on Jul 30, 2025

    @karolz-ms
    Contributor

    The3G thanks for the update. Let us know please if we can help you get to the bottom of this in any way.

  14. The3G commented on Aug 2, 2025

    @The3G
    Author
    info: Aspire.Hosting.Azure.AzureCosmosDBContainerResource[0]
          connecting: AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;AccountEndpoint=https://127.0.0.1:59291;DisableServerCertificateValidation=True;
    info: Aspire.Hosting.Azure.AzureCosmosDBContainerResource[0]
          creating if not exists: appimport
    fail: Aspire.Hosting.Dashboard.ServiceClient.DashboardClient[0]
          Error #1 watching resources.
          Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error reading next message. HttpProtocolException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1). (HttpProtocolError)", DebugException="System.Net.Http.HttpProtocolException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1). (HttpProtocolError)")
           ---> System.Net.Http.HttpProtocolException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1). (HttpProtocolError)
             at System.Net.Http.Http2Connection.ThrowRequestAborted(Exception innerException)
             at System.Net.Http.Http2Connection.Http2Stream.TryReadFromBuffer(Span`1 buffer, Boolean partOfSyncRead)
             at System.Net.Http.Http2Connection.Http2Stream.ReadDataAsync(Memory`1 buffer, HttpResponseMessage responseMessage, CancellationToken cancellationToken)
             at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
             at Grpc.Net.Client.Internal.GrpcCall`2.ReadMessageAsync(Stream responseStream, String grpcEncoding, Boolean singleMessage, CancellationToken cancellationToken)
             at Grpc.Net.Client.Internal.HttpContentClientStreamReader`2.MoveNextCore(CancellationToken cancellationToken)
             --- End of inner exception stack trace ---
             at Grpc.Net.Client.Internal.HttpContentClientStreamReader`2.MoveNextCore(CancellationToken cancellationToken)
             at Grpc.Net.Client.Internal.Retry.RetryCallBaseClientStreamReader`2.MoveNext(CancellationToken cancellationToken)
             at Grpc.Core.AsyncStreamReaderExtensions.ReadAllAsyncCore[T](IAsyncStreamReader`1 streamReader, CancellationToken cancellationToken)+MoveNext()
             at Grpc.Core.AsyncStreamReaderExtensions.ReadAllAsyncCore[T](IAsyncStreamReader`1 streamReader, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
             at Aspire.Dashboard.ServiceClient.DashboardClient.WatchResourcesAsync(RetryContext retryContext, CancellationToken cancellationToken) in /_/src/Aspire.Dashboard/ServiceClient/DashboardClient.cs:line 350
             at Aspire.Dashboard.ServiceClient.DashboardClient.WatchResourcesAsync(RetryContext retryContext, CancellationToken cancellationToken) in /_/src/Aspire.Dashboard/ServiceClient/DashboardClient.cs:line 350
             at Aspire.Dashboard.ServiceClient.DashboardClient.WatchWithRecoveryAsync(Func`3 action, CancellationToken cancellationToken) in /_/src/Aspire.Dashboard/ServiceClient/DashboardClient.cs:line 321
    
  15. reopened this on Aug 2, 2025
  16. The3G commented on Aug 2, 2025

    @The3G
    Author

    different error with new previous 9.5.0; failure to connection using connection string from within the OnResourceReady event inside AppHost.cs using emulator
    AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;AccountEndpoint=https://127.0.0.1:59291;DisableServerCertificateValidation=True;

    info: Aspire.Hosting.Azure.AzureCosmosDBContainerResource[0]
    creating if not exists: appimport

    async Task DatabaseEntityImportFromDirectory(
        AzureCosmosDBContainerResource resource,
        ResourceReadyEvent resourceReadyEvent,
        CancellationToken cancellationToken)
    {
        var hostEnvironment = resourceReadyEvent.Services
                .GetRequiredService<IHostEnvironment>();
        var logger = resourceReadyEvent.Services
            .GetRequiredService<ILogger<AzureCosmosDBContainerResource>>();
    
        string applicationImportPath = Path.Combine(
                hostEnvironment.ContentRootPath.ToLower(),
                hostEnvironment.EnvironmentName.ToLower(),
                "import"
            );
        if (!Directory.Exists(applicationImportPath))
            Directory.CreateDirectory(applicationImportPath);
    
        var resourceConnectionString = await resource
            .Parent.Parent
            .ConnectionStringExpression
            .GetValueAsync(cancellationToken)
            .ConfigureAwait(false);
        
        using(var scoped = logger.BeginScope("importing data from directory"))
        {
            logger.LogInformation("importing data from directory: {Directory}", 
                applicationImportPath);
    
            try 
            {
                logger.LogInformation("connecting: {connectionString}",
                    resourceConnectionString);
    
                CosmosClient resourceClient = new CosmosClient(
                    resourceConnectionString, new CosmosClientOptions
                    {
                        ConsistencyLevel = ConsistencyLevel.Eventual,
                        LimitToEndpoint = resource.IsEmulator(),
                        ConnectionMode = resource.IsEmulator() ? 
                            ConnectionMode.Gateway : ConnectionMode.Direct
                    });
               
                logger.LogInformation("creating if not exists: {databaseName}",
                    resource.Parent.DatabaseName);
    
                await resourceClient.CreateDatabaseIfNotExistsAsync(
                    resource.Parent.DatabaseName);
    
                logger.LogInformation("getting database: {databaseName}",
                    resource.Parent.DatabaseName);
                var resourceDatabase = resourceClient.GetDatabase(
                    resource.Parent.DatabaseName);
    
                logger.LogInformation("creating container: {containerName}",
                    resource.ContainerName);
                
                await resourceDatabase.CreateContainerIfNotExistsAsync(
                    resource.ContainerName, resource.PartitionKeyPath);
            
                var resourceContainer = resourceDatabase.GetContainer(
                    resource.ContainerName);
    
                var importItems = fake.GenerateLazy(10)
                    .Select(item => new 
                    {
                        id = Guid.NewGuid().ToString(),
                        item.Title,
                        item.Description,
                        item.Tags,
                        item.Sensitivity,
                        item.References,
                        item.ImportedBy,
                        item.ImportedOn,
                        item.PublishedBy,
                        item.PublishedOn,
                        filePath = applicationImportPath
                    });
    
                foreach(var item in importItems)
                {
                    logger.LogInformation("importing item: {Title}", item.Title);
                    await resourceContainer.CreateItemAsync(
                        item,
                        new PartitionKey(applicationImportPath),
                        cancellationToken: cancellationToken
                    );
                }
    
            }
            catch(Exception ex)
            {
                logger.LogInformation("exception: {errorMessage}",
                    ex.Message);
            }
            finally
            {
    
            }
        }
    
        await Task.CompletedTask;
    }
    
  17. davidfowl commented on Aug 3, 2025

    @davidfowl
    Collaborator

    The3G what are you looking for here?

  18. The3G commented on Aug 3, 2025

    @The3G
    Author

    David Fowler (@davidfowl) we should be able to connect to the CosmosDb emulator from within the OnResourceReady; however the connection string provided is failing as shown when performing an action to check/create the database. I've a simple repo of the issue here https://github.com/[The3G/CosmosDBOnResourceReady](https://github.com/The3G/CosmosDBOnResourceReady)

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

    area-integrationsazure-cosmosdb

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions