`OwnerDiedError` if dataset owner actor handle get out of scope

Here is the sample code to get OwnerDiedError:

import ray
import time

class W:
    def p(self):
        # or a dataset
        # r_ds = ds.map_batches(...)
        r_ds = [ray.put([1])]
        return r_ds

def start():
    w = W.remote()
    return ray.get(w.p.remote())

r_ds = start()
# or a dataset
# r_ds.write_csv(...)

This is really weird from a user’s perspective, why are we allowing this? How to fix this?
Maybe the object_ref owned by a actor could keep a ref to the actor handle so users do not need to worry about this? For example:

# This make sure actor handle ref count won't be zero
object_ref._owner_actor = actor_handle

Also, this applies to the ray dataset, if you create a dataset in the actor, dataset.save will fail too, how to fix this for dataset?

@fengsp thanks for reporting. this looks like a bug we should fix ASAP.

We will track it in this issue here: [Core] · Issue #35262 · ray-project/ray · GitHub