-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[core] Preserve err type in case of task cancellation due to actor death #57095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edoakes
merged 4 commits into
ray-project:master
from
codope:task-cancellation-exception
Oct 7, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9421de6
[core] Preserve err type in case of task cancellation due to actor death
codope 8806b54
instead of checking state at the submitter, include the information i…
codope c921d91
If we already have the death cause from GCS, use it immediately. Othe…
codope 753f2cd
tasks rejected for non-shutdown reasons get error status
codope File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -662,23 +662,13 @@ void ActorTaskSubmitter::HandlePushTaskReply(const Status &status, | |
| /// Whether or not we will retry this actor task. | ||
| auto will_retry = false; | ||
|
|
||
| if (status.ok() && !is_retryable_exception) { | ||
| if ((status.ok() && reply.was_cancelled_before_running()) || | ||
| status.IsSchedulingCancelled()) { | ||
| HandleTaskCancelledBeforeExecution(status, reply, task_spec); | ||
| } else if (status.ok() && !is_retryable_exception) { | ||
| // status.ok() means the worker completed the reply, either succeeded or with a | ||
| // retryable failure (e.g. user exceptions). We complete only on non-retryable case. | ||
| task_manager_.CompletePendingTask(task_id, reply, addr, reply.is_application_error()); | ||
| } else if (status.IsSchedulingCancelled()) { | ||
| std::ostringstream stream; | ||
| stream << "The task " << task_id << " is canceled from an actor " << actor_id | ||
| << " before it executes."; | ||
| const auto &msg = stream.str(); | ||
| RAY_LOG(DEBUG) << msg; | ||
| rpc::RayErrorInfo error_info; | ||
| error_info.set_error_message(msg); | ||
| error_info.set_error_type(rpc::ErrorType::TASK_CANCELLED); | ||
| task_manager_.FailPendingTask(task_spec.TaskId(), | ||
| rpc::ErrorType::TASK_CANCELLED, | ||
| /*status*/ nullptr, | ||
| &error_info); | ||
| } else { | ||
| bool is_actor_dead = false; | ||
| bool fail_immediately = false; | ||
|
|
@@ -780,6 +770,88 @@ void ActorTaskSubmitter::HandlePushTaskReply(const Status &status, | |
| } | ||
| } | ||
|
|
||
| void ActorTaskSubmitter::HandleTaskCancelledBeforeExecution( | ||
| const Status &status, | ||
| const rpc::PushTaskReply &reply, | ||
| const TaskSpecification &task_spec) { | ||
| const auto task_id = task_spec.TaskId(); | ||
| const auto actor_id = task_spec.ActorId(); | ||
|
|
||
| if (reply.worker_exiting()) { | ||
| // Task cancelled due to actor shutdown - use ACTOR_DIED error. | ||
| // If we have the death cause, use it immediately. Otherwise, | ||
| // wait for it from GCS to provide an accurate error message. | ||
| bool is_actor_dead = false; | ||
| rpc::RayErrorInfo error_info; | ||
| { | ||
| absl::MutexLock lock(&mu_); | ||
| auto queue_pair = client_queues_.find(actor_id); | ||
| if (queue_pair != client_queues_.end()) { | ||
|
Comment on lines
+788
to
+789
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a RAY_CHECK failure in the case where the actor is not dead. I don't like adding more RAY_CHECKs, but I don't see how we can recover if we're handling a PushTaskReply and the actor doesn't have a client_queue_. |
||
| is_actor_dead = queue_pair->second.state_ == rpc::ActorTableData::DEAD; | ||
| if (is_actor_dead) { | ||
| const auto &death_cause = queue_pair->second.death_cause_; | ||
| error_info = gcs::GetErrorInfoFromActorDeathCause(death_cause); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (is_actor_dead) { | ||
| CancelDependencyResolution(task_id); | ||
| RAY_LOG(DEBUG) << "Task " << task_id << " cancelled due to actor " << actor_id | ||
| << " death"; | ||
| task_manager_.FailPendingTask(task_spec.TaskId(), | ||
| error_info.error_type(), | ||
| /*status*/ nullptr, | ||
| &error_info); | ||
| } else if (RayConfig::instance().timeout_ms_task_wait_for_death_info() != 0) { | ||
| CancelDependencyResolution(task_id); | ||
|
|
||
| int64_t death_info_grace_period_ms = | ||
| current_time_ms() + RayConfig::instance().timeout_ms_task_wait_for_death_info(); | ||
|
|
||
| error_info.set_error_type(rpc::ErrorType::ACTOR_DIED); | ||
| error_info.set_error_message( | ||
| "The actor is dead because its worker process has died."); | ||
|
|
||
| { | ||
| absl::MutexLock lock(&mu_); | ||
| auto queue_pair = client_queues_.find(actor_id); | ||
| RAY_CHECK(queue_pair != client_queues_.end()); | ||
| auto &queue = queue_pair->second; | ||
| queue.wait_for_death_info_tasks_.push_back( | ||
| std::make_shared<PendingTaskWaitingForDeathInfo>( | ||
| death_info_grace_period_ms, task_spec, status, error_info)); | ||
| RAY_LOG(INFO).WithField(task_spec.TaskId()) | ||
| << "Task cancelled during actor shutdown, waiting for death info from GCS" | ||
| << ", wait_queue_size=" << queue.wait_for_death_info_tasks_.size(); | ||
| } | ||
| } else { | ||
| CancelDependencyResolution(task_id); | ||
| error_info.set_error_type(rpc::ErrorType::ACTOR_DIED); | ||
| error_info.set_error_message( | ||
| "The actor is dead because its worker process has died."); | ||
| task_manager_.FailPendingTask(task_spec.TaskId(), | ||
| rpc::ErrorType::ACTOR_DIED, | ||
| /*status*/ nullptr, | ||
| &error_info); | ||
| } | ||
| } else { | ||
| // Explicit user cancellation - use TASK_CANCELLED error. | ||
| std::ostringstream stream; | ||
| stream << "The task " << task_id << " is canceled from an actor " << actor_id | ||
| << " before it executes."; | ||
| const auto &msg = stream.str(); | ||
| RAY_LOG(DEBUG) << msg; | ||
| rpc::RayErrorInfo error_info; | ||
| error_info.set_error_message(msg); | ||
| error_info.set_error_type(rpc::ErrorType::TASK_CANCELLED); | ||
| task_manager_.FailPendingTask(task_spec.TaskId(), | ||
| rpc::ErrorType::TASK_CANCELLED, | ||
| /*status*/ nullptr, | ||
| &error_info); | ||
| } | ||
| } | ||
|
|
||
| std::optional<rpc::ActorTableData::ActorState> ActorTaskSubmitter::GetLocalActorState( | ||
| const ActorID &actor_id) const { | ||
| absl::MutexLock lock(&mu_); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.