[Java] fix test hang occasionally when running FailureTest (#13934)

This commit is contained in:
Kai Yang
2021-02-08 18:21:50 +08:00
committed by GitHub
parent 918ad84f08
commit bcf9457abb
6 changed files with 208 additions and 51 deletions
+11 -5
View File
@@ -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;
+2
View File
@@ -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.