Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AfterResourcesCreatedEvent is inconsistently fired #7009

Open
afscrome opened this issue Jan 2, 2025 · 0 comments
Open

AfterResourcesCreatedEvent is inconsistently fired #7009

afscrome opened this issue Jan 2, 2025 · 0 comments

Comments

@afscrome
Copy link
Contributor

afscrome commented Jan 2, 2025

I'm finding the logic for when the AfterResourcesCreatedEvent is fired to be very confusing. Take the following code for example:

var builder = DistributedApplication.CreateBuilder(args);

builder.Services.AddHealthChecks().AddCheck("alwaysUnhealthy", () => HealthCheckResult.Unhealthy());

var one = builder.AddContainer("one", "nginx").WithHealthCheck("alwaysUnhealthy");
var two = builder.AddContainer("two", "nginx");

//two.WaitFor(one);

builder.Eventing.Subscribe<AfterResourcesCreatedEvent>((evt, ct) =>
{
    Console.WriteLine("AfterResourcesCreatedEvent");
    Console.Beep();
    return Task.CompletedTask;
});

builder.Build().Run();

Run this whilst docker is stopped, no resoruces are stated but the AfterResourcesCreatedEvent does get fired.

Image

However if you comment out the //two.WaitFor(one); line above and run the app (whilst docker is still not running), then the AfterResourcesCreatedEvent does not get fired.
Image

The issue here seems to be that when WaitFor is used, the AfterResourcesCreatedEvent is blocked until all health checks become healthy. However the runtime availability is handled by a different flow which does not block AfterResourcesCreatedEvent.

From my point of view, both the above are essentially the same in both cases the containers are waiting on something else before they can start, and so I'd expect either both cases to raise AfterResourcesCreatedEvent or I'd neither to raise the event.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant