Repository navigation
[core] Load restartable DEAD actors on GCS restart - #68721
AshrafAhmed9 wants to merge 2 commits into
Conversation
With GCS FT, a restartable actor that went out of scope (max_restarts=-1 or restarts left, job alive) is DEAD in the actor table but still kept in registered_actors_ for lineage reconstruction. On restart, Initialize built it with the task-spec GcsActor constructor, which checked state != DEAD, so the GCS aborted and crash-looped on every restart. Allow DEAD in that constructor when the actor is restartable. Initialize then rebuilds only what DestroyActor leaves in place for such an actor: it stays in registered_actors_, named_actors_ and its owner's children, with no worker, no created_actors_ entry and no owner polling. Tested with gcs_actor_manager_test. The new restartable DEAD actor test aborts on the CHECK without the fix and passes with it. Closes ray-project#68705 Signed-off-by: Ashrafahmed9 <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates the GCS actor initialization logic to support reloading restartable DEAD actors (e.g., those that went out of scope but still have restarts left) so they can be reconstructed via lineage reconstruction. It also adds corresponding unit tests. A review comment highlights a potential memory leak and lifecycle bug where a restartable DEAD actor is not properly cleaned up when its owner dies because the transition to the OWNER_DIED death cause is not handled in DestroyActor.
| if (actor->GetState() == ray::rpc::ActorTableData::DEAD) { | ||
| // A DEAD actor that got here is restartable (see OnInitializeActorShouldLoad), | ||
| // i.e. it went out of scope. Rebuild what DestroyActor leaves in place: it | ||
| // stays in registered_actors_, named_actors_ and its owner's children, but | ||
| // it has no worker and the owner is no longer polled for it. Registering | ||
| // the child lets the owner's death destroy it. | ||
| if (!actor->IsDetached()) { |
There was a problem hiding this comment.
Memory Leak / Lifecycle Bug when Owner Dies
While registering the restartable DEAD actor under its owner's children_actor_ids_ is intended to let the owner's death destroy it, there is a lifecycle and memory leak issue in DestroyActor when handling already DEAD (out-of-scope) actors whose owners die.
The Issue:
- When the owner dies,
OnWorkerDeadis called, which invokesDestroyActorwithOWNER_DIEDas the death cause. - In
DestroyActor(around line 1113), the death cause of an alreadyDEADactor is only updated if the new cause isREF_DELETED:} else if (mutable_actor_table_data->death_cause().context_case() == ContextCase::kActorDiedErrorContext && death_cause.context_case() == ContextCase::kActorDiedErrorContext && mutable_actor_table_data->death_cause() .actor_died_error_context() .reason() == rpc::ActorDiedErrorContext::OUT_OF_SCOPE && death_cause.actor_died_error_context().reason() == rpc::ActorDiedErrorContext::REF_DELETED) {
- Since
OWNER_DIEDdoes not match this condition, the actor's death cause remainsOUT_OF_SCOPE. - Consequently,
is_restartableis evaluated astrue(sinceOUT_OF_SCOPEwith restarts left is restartable). - Because
is_restartableremainstrue, the actor is never erased fromregistered_actors_orowners_(viaRemoveActorFromOwner). - This results in a permanent memory leak of both the
GcsActorand its owner entry inowners_.
Suggested Fix:
In DestroyActor (around line 1113), update the condition to also allow transition to OWNER_DIED (or any other terminal reason), which will correctly mark the actor as non-restartable and trigger the cleanup:
(death_cause.actor_died_error_context().reason() == rpc::ActorDiedErrorContext::REF_DELETED ||
death_cause.actor_died_error_context().reason() == rpc::ActorDiedErrorContext::OWNER_DIED))There was a problem hiding this comment.
Good catch on the comment, it was wrong and is fixed in ee27c25. Owner death doesn't end an out-of-scope restartable actor because DestroyActor only moves the death cause to REF_DELETED, but that's the same on master without a GCS restart, so I've kept it out of this PR. The owner entry is still needed: RemoveActorFromOwner checks it when the reference is deleted, and the new TestDestroyReloadedRestartableDeadActor crashes there without it.
The owner entry restored in Initialize is needed by RemoveActorFromOwner when DestroyActor runs with REF_DELETED, not for owner death. Fix the comment and add a test that destroys a reloaded restartable DEAD actor. Signed-off-by: Ashrafahmed9 <[email protected]>
Description
With GCS fault tolerance, a restartable actor that went out of scope (
DEAD,OUT_OF_SCOPE,max_restarts=-1or restarts left, job alive) makes the restarted GCS abort inGcsActorManager::Initialize.OnInitializeActorShouldLoadlets the actor through, but the task-specGcsActorconstructor checksstate != DEAD, so every new GCS crashes on the same row.This keeps the actor loaded, so it's still available for lineage reconstruction after a GCS restart, the same as without a restart:
DEADonly whenIsActorRestartableis true.Initializerebuilds only whatDestroyActorleaves in place for such an actor. It stays inregistered_actors_andnamed_actors_and is registered under its owner'schildren_actor_ids_, becauseRemoveActorFromOwnerchecks for that entry when the reference is finally deleted (REF_DELETED). It gets nocreated_actors_or worker entry, and the owner isn't polled again, because that poll already returned before the actor went out of scope.Related issues
Closes #68705
No open PR or other issue covers this (searched open PRs for 68705 and for the GCS actor init path). #66073 fixed a different crash in the same init path, for actors without a task spec.
Additional information
Not changed here:
DestroyActoronly moves an out-of-scope actor's death cause toREF_DELETED, so an owner dying (OWNER_DIED) doesn't end a restartable out-of-scope actor. That's the same on master without a GCS restart, so I've kept it out of this PR.One limitation: since the owner isn't polled again, an owner that dies while the GCS is down is only noticed if its worker or node failure is reported to the new GCS. Polling the owner again would catch that case, but the owner has already dropped its reference, so I left it out. Happy to change that if you prefer.
Testing:
bazel test //src/ray/gcs/actor/tests:gcs_actor_manager_testpasses (51 tests). The newTestInitializeLoadsRestartableDeadActoraborts on thestate != DEADcheck without the fix.TestDestroyReloadedRestartableDeadActordeletes the reference after the restart and checks the actor is removed; without the owner registration it aborts inRemoveActorFromOwner.TestInitializeDropsNonRestartableDeadActorchecks that amax_restarts=0actor is still dropped.I used Claude Code (AI assistance) for this change. I reviewed every changed line and ran the tests above locally.