Fix waiting resource start and stop command behavior#18795
Draft
afscrome wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18795Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18795" |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Aspire Hosting resource lifecycle command handling to improve behavior for resources in the Waiting state—allowing Stop to cancel a pending dependency-blocked start and ensuring user-triggered Start remains usable across subsequent runs by treating it as a non-blocking start request.
Changes:
- Enable
StopforWaitingresources and implement cancellation by moving the resource back toNotStartedwithout calling DCP stop. - Introduce
RequestStartResourceAsyncto decouple user start requests from waiting/creation completion, observing failures in the background. - Add orchestration and command-state unit tests for waiting-resource start/stop paths.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.Tests/ResourceCommandAnnotationTests.cs | Updates expected command state so stop is enabled while a resource is Waiting. |
| tests/Aspire.Hosting.Tests/Orchestrator/ApplicationOrchestratorTests.cs | Adds tests for waiting-stop cancellation behavior and non-blocking start requests; allows injecting a tracking DCP executor. |
| src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs | Implements non-blocking start requests, waiting-stop cancellation to NotStarted, and explicit startup-abort detection during dependency waits. |
| src/Aspire.Hosting/Dcp/DcpExecutor.cs | Handles ResourceStartAbortedException as a non-failure (debug log only). |
| src/Aspire.Hosting/ApplicationModel/ResourceStartAbortedException.cs | Adds an internal exception type to represent explicit startup abort while waiting. |
| src/Aspire.Hosting/ApplicationModel/CommandsConfigurationExtensions.cs | Switches Start command to call RequestStartResourceAsync and adjusts Stop enablement behavior for Waiting. |
Comment on lines
+124
to
+134
| // If the wait ended because the state was manually moved out of Waiting to anything | ||
| // other than Starting, treat that as an explicit cancellation of this startup attempt. | ||
| // This is used by the Stop command to abort a dependency-blocked start. | ||
| if (completedTask == waitForNonWaitingStateTask && waitForNonWaitingStateTask.IsCompletedSuccessfully) | ||
| { | ||
| var state = waitForNonWaitingStateTask.Result.Snapshot.State?.Text; | ||
| if (!string.Equals(state, KnownResourceStates.Starting, StringComparisons.ResourceState)) | ||
| { | ||
| throw new ResourceStartAbortedException(@event.Resource.Name, state); | ||
| } | ||
| } |
Comment on lines
26
to
32
| executeCommand: async context => | ||
| { | ||
| var orchestrator = context.Services.GetRequiredService<ApplicationOrchestrator>(); | ||
|
|
||
| await orchestrator.StartResourceAsync(context.ResourceName, context.CancellationToken).ConfigureAwait(false); | ||
| await orchestrator.RequestStartResourceAsync(context.ResourceName, context.CancellationToken).ConfigureAwait(false); | ||
| return new ExecuteCommandResult { Success = true, Message = string.Format(CultureInfo.InvariantCulture, CommandStrings.ResourceStarted, resource.GetResolvedDisplayResourceName(context.ResourceName)) }; | ||
| }, |
Contributor
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This fixes two related resource lifecycle issues around dependency waits and force start behavior. In the previous behavior, a resource in
Waitingcould not be canceled withStop, and after force starting once, a subsequentWaitingrun could no longer be force started.The change updates lifecycle command handling so:
Stopis enabled forWaitingresources and cancels the pending startup by moving the resource back toNotStarted.Startis treated as a start request that does not block command execution while dependency waits are in progress, so force start remains usable on subsequent runs.Targeted tests were updated and added to cover command state behavior and waiting-resource start/stop orchestration paths.
Fixes #14812
Fixes #14813
Checklist
<remarks />and<code />elements on your triple slash comments?