# Cleanup pattern for client disconnection in actors/tasks

**URL:** <https://discuss.ray.io/t/cleanup-pattern-for-client-disconnection-in-actors-tasks/9036>\
**Category:** Ray Core\
**Created:** [January 19, 2023, 7:53pm UTC](https://discuss.ray.io/t/cleanup-pattern-for-client-disconnection-in-actors-tasks/9036 "2023-01-19T19:53:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_B](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/michael_b/32/3746_2.png) [@Michael\_B](https://discuss.ray.io/u/Michael_B)\
**Post date:** [January 19, 2023, 7:53pm UTC](https://discuss.ray.io/t/cleanup-pattern-for-client-disconnection-in-actors-tasks/9036/1 "2023-01-19T19:53:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![zhz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/zhz/32/12_2.png) [@zhz](https://discuss.ray.io/u/zhz)\
**Post date:** [January 19, 2023, 8:09pm UTC](https://discuss.ray.io/t/cleanup-pattern-for-client-disconnection-in-actors-tasks/9036/2 "2023-01-19T20:09:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_B](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/michael_b/32/3746_2.png) [@Michael\_B](https://discuss.ray.io/u/Michael_B)\
**Post date:** [January 19, 2023, 8:18pm UTC](https://discuss.ray.io/t/cleanup-pattern-for-client-disconnection-in-actors-tasks/9036/3 "2023-01-19T20:18:54Z")

</div>

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.
