You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Eric Erhardt (@eerhardt) and I chatted. We think the main issue is that as soon as app.StopAsync() is called, the resource service and ApplicationExecutor stops listening to resource changes. So even if DcpOptions.DeleteResourcesOnShutdown is set, there is no way for the Aspire model to learn that the container (or any resource for that matter) has changed state, or was deleted.
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.)
Karol Zadora-Przylecki (@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.
Damian Edwards (@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)
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 Eric Erhardt (@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.
I think shutting down in dispose would be better (implement IDisposable or IAsyncDisposable)
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 ResourceNotificationService to not kill the loop until it's disposed so that notifications sent after app host stopping but before disposal can be seen.
Is the work left here to update Aspire.Hosting to issue the relevant two-phase commands to DCP appropriately, i.e. Stop() -> stop, Dispose() -> shutdown?
Yes, I am working on this as we speak. Specifically, on adding a new property to DcpExecutor that determines whether StopAsync() waits for resource cleanup to be complete or not. That will then be leveraged by test application builder. Should have a PR out for review sometime later today.
Activity
karolz-ms commentedon Jul 15, 2024
Eric Erhardt (@eerhardt) and I chatted. We think the main issue is that as soon as
app.StopAsync()is called, the resource service and ApplicationExecutor stops listening to resource changes. So even ifDcpOptions.DeleteResourcesOnShutdownis set, there is no way for the Aspire model to learn that the container (or any resource for that matter) has changed state, or was deleted.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.)
ealeykin commentedon Nov 16, 2024
Karol Zadora-Przylecki (@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.
davidfowl commentedon Jan 14, 2025
Damian Edwards (@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)
DamianEdwards commentedon Jan 14, 2025
Is there an existing signal for that or would we need to do something custom?
davidfowl commentedon Jan 14, 2025
I think shutting down in dispose would be better (implement IDisposable or IAsyncDisposable)
karolz-ms commentedon Jan 14, 2025
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 Eric Erhardt (@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.
DamianEdwards commentedon Jan 14, 2025
Regardless, it seems it would still make sense to change
ResourceNotificationServiceto not kill the loop until it's disposed so that notifications sent after app host stopping but before disposal can be seen.Don't end resource notifications until service is disposed
33 remaining items
DamianEdwards commentedon Feb 5, 2025
Is the work left here to update
Aspire.Hostingto issue the relevant two-phase commands to DCP appropriately, i.e. Stop() -> stop, Dispose() -> shutdown?davidfowl commentedon Feb 6, 2025
Yes we never merged #4878 (comment)
DamianEdwards commentedon Feb 6, 2025
David Fowler (@davidfowl) OK so DCP got updates to ensure it can send final states now and we just need to merge your changes?
davidfowl commentedon Feb 6, 2025
I assume we also need to call the new APIs in DCP yep.
DamianEdwards commentedon Feb 6, 2025
OK, is this correctly assigned? Karol Zadora-Przylecki (@karolz-ms) are you planning to do the work on the Aspire side for this?
karolz-ms commentedon Feb 6, 2025
Yes, I am working on this as we speak. Specifically, on adding a new property to
DcpExecutorthat determines whetherStopAsync()waits for resource cleanup to be complete or not. That will then be leveraged by test application builder. Should have a PR out for review sometime later today.karolz-ms commentedon Feb 7, 2025
Should be resolved with #7446
davidfowl commentedon Feb 10, 2025
I think we need a test to actually use this pattern to see if we need more changes to the app model codez.
DamianEdwards commentedon Feb 10, 2025
I can update the samples tests to do it. Is there are code snippet someone can point me at?
eerhardt commentedon Feb 10, 2025
Also #7477 could use this as well.
cc Sébastien Ros (@sebastienros)