mirror of
https://github.com/wassname/ray.git
synced 2026-07-27 11:26:41 +08:00
[Java] fix test hang occasionally when running FailureTest (#13934)
This commit is contained in:
@@ -161,15 +161,19 @@ CoreWorkerProcess::CoreWorkerProcess(const CoreWorkerOptions &options)
|
||||
// RayConfig is generated in Java_io_ray_runtime_RayNativeRuntime_nativeInitialize
|
||||
// for java worker or in constructor of CoreWorker for python worker.
|
||||
ray::stats::Init(global_tags, options_.metrics_agent_port);
|
||||
|
||||
// NOTE(kfstorm): std::atexit should be put at the end of `CoreWorkerProcess`
|
||||
// constructor. We assume that spdlog has been initialized before this line. When the
|
||||
// process is exiting, `HandleAtExit` will be invoked before destructing spdlog static
|
||||
// variables. We explicitly destruct `CoreWorkerProcess` instance in the callback to
|
||||
// ensure the static `CoreWorkerProcess` instance is destructed while spdlog is still
|
||||
// usable. This prevents crashing (or hanging) when using `RAY_LOG` in
|
||||
// `CoreWorkerProcess` destructor.
|
||||
RAY_CHECK(std::atexit(CoreWorkerProcess::HandleAtExit) == 0);
|
||||
}
|
||||
|
||||
CoreWorkerProcess::~CoreWorkerProcess() {
|
||||
RAY_LOG(INFO) << "Destructing CoreWorkerProcess. pid: " << getpid();
|
||||
{
|
||||
// Check that all `CoreWorker` instances have been removed.
|
||||
absl::ReaderMutexLock lock(&worker_map_mutex_);
|
||||
RAY_CHECK(workers_.empty());
|
||||
}
|
||||
RAY_LOG(DEBUG) << "Stats stop in core worker.";
|
||||
// Shutdown stats module if worker process exits.
|
||||
ray::stats::Shutdown();
|
||||
@@ -183,6 +187,8 @@ void CoreWorkerProcess::EnsureInitialized() {
|
||||
<< "shutdown.";
|
||||
}
|
||||
|
||||
void CoreWorkerProcess::HandleAtExit() { instance_.reset(); }
|
||||
|
||||
std::shared_ptr<CoreWorker> CoreWorkerProcess::TryGetWorker(const WorkerID &worker_id) {
|
||||
if (!instance_) {
|
||||
return nullptr;
|
||||
|
||||
@@ -265,6 +265,8 @@ class CoreWorkerProcess {
|
||||
/// \return Void.
|
||||
static void EnsureInitialized();
|
||||
|
||||
static void HandleAtExit();
|
||||
|
||||
/// Get the `CoreWorker` instance by worker ID.
|
||||
///
|
||||
/// \param[in] workerId The worker ID.
|
||||
|
||||
Reference in New Issue
Block a user