From d4324a4a8f886f60cd5f12356b97466e86a78b89 Mon Sep 17 00:00:00 2001 From: fangfengbin <869218239a@zju.edu.cn> Date: Fri, 24 Jul 2020 15:36:49 +0800 Subject: [PATCH] fix java coreworker crash (#9674) --- src/ray/core_worker/actor_manager.cc | 8 +++++--- src/ray/core_worker/actor_manager.h | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ray/core_worker/actor_manager.cc b/src/ray/core_worker/actor_manager.cc index 8cdd8676c..04b2536ce 100644 --- a/src/ray/core_worker/actor_manager.cc +++ b/src/ray/core_worker/actor_manager.cc @@ -89,9 +89,11 @@ bool ActorManager::AddActorHandle(std::unique_ptr actor_handle, auto actor_notification_callback = std::bind(&ActorManager::HandleActorStateNotification, this, std::placeholders::_1, std::placeholders::_2); - - RAY_CHECK_OK(gcs_client_->Actors().AsyncSubscribe( - actor_id, actor_notification_callback, nullptr)); + { + absl::MutexLock lock(&gcs_client_mutex_); + RAY_CHECK_OK(gcs_client_->Actors().AsyncSubscribe( + actor_id, actor_notification_callback, nullptr)); + } if (!RayConfig::instance().gcs_actor_service_enabled()) { RAY_CHECK(reference_counter_->SetDeleteCallback( diff --git a/src/ray/core_worker/actor_manager.h b/src/ray/core_worker/actor_manager.h index a63f774ca..9a4c46ac0 100644 --- a/src/ray/core_worker/actor_manager.h +++ b/src/ray/core_worker/actor_manager.h @@ -132,8 +132,11 @@ class ActorManager { void HandleActorStateNotification(const ActorID &actor_id, const gcs::ActorTableData &actor_data); - /// GCS client - std::shared_ptr gcs_client_; + /// Mutex to protect the gcs_client_ field. + /// NOTE: Now gcs client is not thread safe, so we add lock protection. + mutable absl::Mutex gcs_client_mutex_; + /// GCS client. + std::shared_ptr gcs_client_ GUARDED_BY(gcs_client_mutex_); /// Interface to submit tasks directly to other actors. std::shared_ptr direct_actor_submitter_;