microsoft / microsoft/aspire

`OnBeforeResourceStart` events fired out of order

Open
#14,952 1 comment 0 reactions 1 assignee Claimed by @karolz-ms View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

If you have a child resource waiting on a parent resource A, I'd expect the `BeforeResourceStartedEvent` for the parent to fire befor ethe child. But this doesn't seem to be the case

### Expected Behavior

_No response_

### Steps To Reproduce

Run the following code. I'd expect `OnBeforeResourceStarted + parent` to always be printed first, and `OnBeforeResourceStarted + child` to come second. But child always comes first for me.

```cs
var parent = builder.AddExecutable("parent", "pwsh", ".")
.OnBeforeResourceStarted(async (res, _, _) =>
{
Console.WriteLine("OnBeforeResourceStarted + " + res.Name);
})
// .WithExplicitStart()
;

var child = builder.AddExecutable("child", "pwsh", ".")
.WaitFor(parent)
.WithEnvironment(x =>
{
Console.WriteLine("WithEnvironment");
})
.OnBeforeResourceStarted((res, _, _) =>
{
Console.WriteLine("OnBeforeResourceStarted + " + res.Name);
return Task.CompletedTask;
});
```

Image

This becomes most clear if you make the parent `WithExplicitStart()` - I wouldn't expect the child event to fire until the resource is started, but you actually see the child event, without the parent event at all.

Image

### Exceptions (if any)

_No response_

### .NET Version info

13.3.0-preview.1.26153.13+bd9fc4f59591806b227e8602b32d1f4d9045b86b

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.