Cleanup pattern for client disconnection in actors/tasks

What is the best pattern for doing cleanup within tasks/actors when the client is disconnected or shuts down? The specific problem is that our tasks/actors create a lot of temporary stuff in AWS while they are running and if possible, we would like to run a cleanup function if the client shuts down unexpectedly. Is there a task/actor-side exception/signal that we could handle that would give anything running in ray a last chance to shut down gracefully in this scenario?

Thanks @Michael_B , to confirm, you are using Ray Client right? Also which version of Ray?

Right, I have a cluster and am concerned about the remoted actors/tasks not having a last-chance to cleanup gracefully if the client disconnects unexpectedly, since presumably when that happens, raylet shuts the process down . We’re using Ray 2.2.0.