Skip to content
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

[Core] Fix the segfault from Opencensus upon shutdown (#36906) #37311

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ray/core_worker/core_worker_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ CoreWorkerProcessImpl::CoreWorkerProcessImpl(const CoreWorkerOptions &options)

CoreWorkerProcessImpl::~CoreWorkerProcessImpl() {
RAY_LOG(INFO) << "Destructing CoreWorkerProcessImpl. pid: " << getpid();
RAY_LOG(DEBUG) << "Stats stop in core worker.";
// Shutdown stats module if worker process exits.
stats::Shutdown();
if (options_.enable_logging) {
Expand Down
22 changes: 13 additions & 9 deletions src/ray/stats/metric_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ OpenCensusProtoExporter::OpenCensusProtoExporter(const int port,
const std::string address,
const WorkerID &worker_id)
: client_call_manager_(io_service), worker_id_(worker_id) {
absl::MutexLock l(&mu_);
client_.reset(new rpc::MetricsAgentClient(address, port, client_call_manager_));
};

Expand Down Expand Up @@ -202,15 +203,18 @@ void OpenCensusProtoExporter::ExportViewData(
}
}

client_->ReportOCMetrics(
request_proto, [](const Status &status, const rpc::ReportOCMetricsReply &reply) {
RAY_UNUSED(reply);
if (!status.ok()) {
RAY_LOG_EVERY_N(WARNING, 10000)
<< "Export metrics to agent failed: " << status
<< ". This won't affect Ray, but you can lose metrics from the cluster.";
}
});
{
absl::MutexLock l(&mu_);
client_->ReportOCMetrics(
request_proto, [](const Status &status, const rpc::ReportOCMetricsReply &reply) {
RAY_UNUSED(reply);
if (!status.ok()) {
RAY_LOG_EVERY_N(WARNING, 10000)
<< "Export metrics to agent failed: " << status
<< ". This won't affect Ray, but you can lose metrics from the cluster.";
}
});
}
}

} // namespace stats
Expand Down
4 changes: 3 additions & 1 deletion src/ray/stats/metric_exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ class OpenCensusProtoExporter final : public opencensus::stats::StatsExporter::H
private:
/// Call Manager for gRPC client.
rpc::ClientCallManager client_call_manager_;
/// Lock to protect the client
mutable absl::Mutex mu_;
/// Client to call a metrics agent gRPC server.
std::unique_ptr<rpc::MetricsAgentClient> client_;
std::unique_ptr<rpc::MetricsAgentClient> client_ GUARDED_BY(&mu_);
/// The worker ID of the current component.
WorkerID worker_id_;
};
Expand Down
1 change: 1 addition & 0 deletions src/ray/stats/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ static inline void Shutdown() {
metrics_io_service_pool = nullptr;
exporter = nullptr;
StatsConfig::instance().SetIsInitialized(false);
RAY_LOG(INFO) << "Stats module has shutdown.";
}

} // namespace stats
Expand Down