-
Notifications
You must be signed in to change notification settings - Fork 540
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
Can't WaitForResourceAsync KnownResourceStates.Finished #4878
Comments
@eerhardt and I chatted. We think the main issue is that as soon as It would probably make sense to change this behavior and differentiate between stopping the application (which would stop application executables and containers, but preserve the Aspire model and its ability to get state updates) vs disposing of the application (which would dispose of the model, stop DCP orchestrator etc.) |
@karolz-ms I'm observing the same behavior even before StopAsync - not getting a Finished notification when the target host exits. Well, from time to time I get it, but most of the time it's stuck on waiting till the timeout. |
@DamianEdwards this is the code you added to unhook the notification service on shutdown automatically. We'd need to allow listening to changes past the stopping of the application (but before disposal) |
Is there an existing signal for that or would we need to do something custom? |
I think shutting down in dispose would be better (implement IDisposable or IAsyncDisposable) |
This issue covers 3 different use cases: stopping a resource vs deleting a resource vs disposing of the application. We should recognize that they are different and are useful for different use cases. We should be clear about what use case we are talking about, what mechanism(s) we want to use for that use case(s), and what works as expected vs needs improvement. Some thoughts on the original use case that prompted @eerhardt to open this issue follow. To me the right mechanism seems deleting the container that is using a volume. When the container is deleted, the app host should receive a notification and can proceed to delete the container volume that the container was using. This is all supported by the app orchestrator today and should work, provided the app model allows the app host code to do this (not 100% sure, some work may be necessary). Alternatively the orchestrator could support marking the volume as "should be deleted when the app shuts down". That would be a new feature for the orchestrator. The test could then dispose the whole app and rely on automatic cleanup by app orchestrator. Stopping a container in this scenario is not sufficient, because a stopped container is still holding a reference to the volume. That is just how Docker/Podman work. Disposing the app host while listening to notifications is not going to work because (once #7098 is merged) disposing the app triggers wholesale resource cleanup and orchestrator shutdown. The app orchestrator does not make any guarantees about the order in which resources are cleaned up, and it does not guarantee sending notifications about resources being cleaned up either. It just tries to get the machine to clean state as quickly as possible. |
Regardless, it seems it would still make sense to change |
Agreed |
It turns out when you let DCP shutdown it may not put resources in the Finished state. I observed Stopping and then nothing. This doesn't feel like a bug but we need to decide if this is the desired behavior. https://github.com/dotnet/aspire/compare/davidfowl/stop-listeing-ondispose?expand=1 |
Yeah this is what I saw IIRC. If you wait a bit after calling |
We can definitively do this in DCP. To a large degree it is possible already, just not through a single call. Namely, both |
If it's easy we can do it in 9.1 but we don't have plans to take advantage of this in 9.1 |
Synced up with @eerhardt offline. What @davidfowl (stop resources call + stop DCP call) seems to meet expectations for the scenario. |
We should re-triage, this might be necessary to prevent #7215 |
Is the work left here to update |
Yes we never merged #4878 (comment) |
@davidfowl OK so DCP got updates to ensure it can send final states now and we just need to merge your changes? |
I assume we also need to call the new APIs in DCP yep. |
OK, is this correctly assigned? @karolz-ms are you planning to do the work on the Aspire side for this? |
Yes, I am working on this as we speak. Specifically, on adding a new property to |
Should be resolved with #7446 |
I think we need a test to actually use this pattern to see if we need more changes to the app model codez. |
I can update the samples tests to do it. Is there are code snippet someone can point me at? |
Also #7477 could use this as well. |
Is there an existing issue for this?
Describe the bug
It's not possible to get notification when a resource has been stopped/finished when after
await app.StopAsync();
.I'm trying to write a test that uses a Docker Volume, and when the test is done, it deletes the volume. However, the volume is still in use even after
await app.StopAsync();
returns, which means the container using the volume is still running.I'd like a way to get notified when the resource/container is finished so I can delete the volume.
One reason this isn't possible today is that WaitForResourceAsync cancels once the app is stopping here:
aspire/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs
Lines 89 to 93 in 681f2e7
Once the app is stopping, it cancels this loop, which means we won't get more notifications about the resource.
Expected Behavior
I'd like to get a notification when the container is finished.
Steps To Reproduce
Exceptions (if any)
No response
.NET Version info
No response
Anything else?
cc @DamianEdwards @karolz-ms @mitchdenny
The text was updated successfully, but these errors were encountered: