Skip to content

OnBeforeResourceStarted being fired twice on restart #13068

@afscrome

Description

@afscrome

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If you restart a resource, the OnBeforeResourceStarted event seems to get fired twice if you try to restart a resource.

Expected Behavior

The event should only get fired a single time for each restart.

Image

Steps To Reproduce

  1. Start the following app host
  2. On the dashboard restart the nginx resource (both restart and stop/start reproduce)
  3. Observe the "Before Start" messages in the console output
var builder = DistributedApplication
    .CreateBuilder(args);

var foo = builder.AddContainer("nginx", "nginx")
    .OnBeforeResourceStarted((_, _, _) =>
    {
        Console.WriteLine($"Before Start {DateTime.Now}");
        return Task.CompletedTask;
    });

builder.Build().Run();

Exceptions (if any)

Logs:

During startup, the "Before Start" line is only printed once as you'd expect. but the restart at the end of logs shows two events fired at pretty much the same time.

info: Aspire.Hosting.DistributedApplication[0]
      Aspire version: 13.0.0+7512c2944094a58904b6c803aa824c4a4ce42e11
info: Aspire.Hosting.DistributedApplication[0]
      Distributed application starting.
info: Aspire.Hosting.DistributedApplication[0]
      Application host directory is: S:\DotNetConf\DotNetConf.AppHost
Before Start 20/11/2025 13:53:19
info: Aspire.Hosting.DistributedApplication[0]
      Distributed application started. Press Ctrl+C to shut down.
info: Aspire.Hosting.DistributedApplication[0]
      Now listening on: https://localhost:17031
info: Aspire.Hosting.DistributedApplication[0]
      Login to the dashboard at https://localhost:17031/login?t=0d33a1e5059de528e9cba4cb8b116462
Before Start 20/11/2025 13:53:33
Before Start 20/11/2025 13:53:33

.NET Version info

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions