Skip to content

Commit

Permalink
Fix by caching call metric recording stuff in async request
Browse files Browse the repository at this point in the history
PR grpc#32106 caused msan errors in some tests while de-referencing the
server object where async calls are active after the server is
destroyed. Instead cache the ServerMetricRecorder pointer.
  • Loading branch information
yousukseung committed Feb 3, 2023
1 parent 50b552e commit e93a217
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/grpcpp/server_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class ServerInterface : public internal::CallHook {
internal::Call call_wrapper_;
internal::InterceptorBatchMethodsImpl interceptor_methods_;
bool done_intercepting_;
bool call_metric_recording_enabled_;
experimental::ServerMetricRecorder* server_metric_recorder_;
};

/// RegisteredAsyncRequest is not part of the C++ API
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/server/server_cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ ServerInterface::BaseAsyncRequest::BaseAsyncRequest(
interceptor_methods_.SetCall(&call_wrapper_);
interceptor_methods_.SetReverse();
call_cq_->RegisterAvalanching(); // This op will trigger more ops
call_metric_recording_enabled_ = server_->call_metric_recording_enabled();
server_metric_recorder_ = server_->server_metric_recorder();
}

ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() {
Expand All @@ -170,8 +172,8 @@ bool ServerInterface::BaseAsyncRequest::FinalizeResult(void** tag,
}
return true;
}
context_->set_call(call_, server_->call_metric_recording_enabled(),
server_->server_metric_recorder());
context_->set_call(call_, call_metric_recording_enabled_,
server_metric_recorder_);
context_->cq_ = call_cq_;
if (call_wrapper_.call() == nullptr) {
// Fill it since it is empty.
Expand Down

0 comments on commit e93a217

Please sign in to comment.