Skip to content

backgroud service can't stop when use dotnet watch #50952

@niltor

Description

@niltor

Describe the bug

When I using dotnet run command or F5(with VS) to start the AspireHost, the migrations service can stop (The dashboard show Finished):
Image

But when I using dotnet watch to run the AspireHost, the service still Running(Maybe stoped, but dashboard think as running):

Image

Since other services will not start until the migration is completed, in this case, other services will never run.

The Console from terminal:

Image

The console log from dashboard:

Image

The code:

   protected override async Task ExecuteAsync(CancellationToken cancellationToken)
   {
       using var activity = _activitySource.StartActivity(
           "Migrating database",
           ActivityKind.Client
       );
       try
       {
           using var scope = serviceProvider.CreateScope();
           var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();

           await RunMigrationAsync(dbContext, cancellationToken);
           await SeedDataAsync(dbContext, cancellationToken);
       }
       catch (Exception ex)
       {
           activity?.AddException(ex);
           throw;
       }
       hostApplicationLifetime.StopApplication();
   }

Expected Behavior

migrations service should stopped as normal when using dotnet watch.

Steps To Reproduce

using the dotnet watch to start aspire host.

Exceptions (if any)

No response

.NET Version info

.NET9 and .NET10 RC1

Anything else?

.NET Aspire 9.4.1 and .NET Aspire 9.4.2

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions