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

Waiting for health status of a stopped resource #7186

Open
1 task done
JamesNK opened this issue Jan 21, 2025 · 5 comments
Open
1 task done

Waiting for health status of a stopped resource #7186

JamesNK opened this issue Jan 21, 2025 · 5 comments
Assignees
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Milestone

Comments

@JamesNK
Copy link
Member

JamesNK commented Jan 21, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

WaitUntilHealthyAsync will stop waiting, or not attempt to wait, if the resource is in an exited/finished state:

if (snapshot.State?.Text == KnownResourceStates.FailedToStart)
{
resourceLogger.LogError(
"Dependency resource '{ResourceName}' failed to start.",
dependency.Name
);
throw new DistributedApplicationException($"Dependency resource '{dependency.Name}' failed to start.");
}
else if (snapshot.State!.Text == KnownResourceStates.Finished || snapshot.State!.Text == KnownResourceStates.Exited)
{
resourceLogger.LogError(
"Resource '{ResourceName}' has entered the '{State}' state prematurely.",
dependency.Name,
snapshot.State.Text
);
throw new DistributedApplicationException(
$"Resource '{dependency.Name}' has entered the '{snapshot.State.Text}' state prematurely."
);
}

It makes sense to stop waiting if resources can't be started again. I think this was written before we had start/restart commands.

Expected Behavior

Should WaitUntilHealthyAsync wait for a healthy status and ignore if the resource stops?

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

No response

Anything else?

No response

@JamesNK JamesNK added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jan 21, 2025
@JamesNK
Copy link
Member Author

JamesNK commented Jan 21, 2025

cc @davidfowl

@JamesNK
Copy link
Member Author

JamesNK commented Jan 21, 2025

Offline discussion:

If a resource is started and it must wait for a resource that is stopped/finished then there are only two options.

  1. The started resource waits until the other resource is started again and becomes healthy, or
  2. The started resource fails and enters a FailedToStart state. The user must start the waited on resource first, then try again.

Option 1 is a better user experience. We don't force people to understand the right order when starting multiple resources. However option 2 is useful for tests where we want tests to fail fast.

We could add a flag to control the behavior, with normal usage to be to wait (option 1) and tests are configured to fail (option 2).

@JamesNK JamesNK added the untriaged New issue has not been triaged label Jan 21, 2025
@afscrome
Copy link
Contributor

We could add a flag to control the behavior, with normal usage to be to wait (option 1) and tests are configured to fail (option 2).

Could DistributedApplicationOptions.DisableDashboard be used as that flag? If the dashboard is present, wait for a future start. If dashboard isn't, fail.

@davidfowl
Copy link
Member

I think we would add a new flag,

@davidfowl davidfowl removed the untriaged New issue has not been triaged label Feb 2, 2025
@davidfowl davidfowl self-assigned this Feb 2, 2025
@davidfowl davidfowl added this to the 9.1 milestone Feb 2, 2025
@davidfowl
Copy link
Member

I'm going to work on this in 9.1. There will be a default wait behavior determined by if the dashboard is enabled or not. It'll be possible to override it on the per call basis (ConfigureAwait 😄 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

No branches or pull requests

3 participants