Skip to content

Commit ea0f459

Browse files
authored
修复日志打印时core dump问题 (#56)
1 parent 252cf1d commit ea0f459

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

polaris/plugin/server_connector/grpc_server_connector.cpp

+28-9
Original file line numberDiff line numberDiff line change
@@ -918,25 +918,44 @@ void BlockRequest::OnSuccess(::v1::Response* response) {
918918
server_code_ = ToPolarisServerCode(response->code().value());
919919
if (server_code_ != kServerCodeServerError) {
920920
if (POLARIS_LOG_ENABLE(kTraceLogLevel)) {
921-
POLARIS_LOG(LOG_TRACE, "%s for request[%s] to server[%s:%d] success with response[%s]",
922-
PolarisRequestTypeStr(request_type_), message_->ShortDebugString().c_str(),
923-
instance_->GetHost().c_str(), instance_->GetPort(), response->ShortDebugString().c_str());
921+
if (instance_ != nullptr) {
922+
POLARIS_LOG(LOG_TRACE, "%s for request[%s] to server[%s:%d] success with response[%s]",
923+
PolarisRequestTypeStr(request_type_), message_->ShortDebugString().c_str(),
924+
instance_->GetHost().c_str(), instance_->GetPort(), response->ShortDebugString().c_str());
925+
}else{
926+
POLARIS_LOG(LOG_TRACE, "%s for request[%s] to server[%s:%d] success with response[%s]",
927+
PolarisRequestTypeStr(request_type_), message_->ShortDebugString().c_str(),
928+
host_.c_str(), port_, response->ShortDebugString().c_str());
929+
}
924930
}
925931
promise_->SetValue(response);
926932
} else { // 请求处理失败
927933
promise_->SetError(kReturnServerError);
928-
POLARIS_LOG(LOG_ERROR, "%s for request[%s] to server[%s:%d] error with response[%s]",
929-
PolarisRequestTypeStr(request_type_), message_->ShortDebugString().c_str(),
930-
instance_->GetHost().c_str(), instance_->GetPort(), response->ShortDebugString().c_str());
934+
if (instance_ != nullptr) {
935+
POLARIS_LOG(LOG_ERROR, "%s for request[%s] to server[%s:%d] error with response[%s]",
936+
PolarisRequestTypeStr(request_type_), message_->ShortDebugString().c_str(),
937+
instance_->GetHost().c_str(), instance_->GetPort(), response->ShortDebugString().c_str());
938+
}else{
939+
POLARIS_LOG(LOG_ERROR, "%s for request[%s] to server[%s:%d] error with response[%s]",
940+
PolarisRequestTypeStr(request_type_), message_->ShortDebugString().c_str(),
941+
host_.c_str(), port_, response->ShortDebugString().c_str());
942+
}
931943
delete response;
932944
}
933945
connector_.UpdateCallResult(this);
934946
}
935947

936948
void BlockRequest::OnFailure(const std::string& message) {
937-
POLARIS_LOG(LOG_ERROR, "%s for request[%s] to server[%s:%d] with rpc error %s", PolarisRequestTypeStr(request_type_),
938-
message_->ShortDebugString().c_str(), instance_->GetHost().c_str(), instance_->GetPort(),
939-
message.c_str());
949+
if (instance_ != nullptr) {
950+
POLARIS_LOG(LOG_ERROR, "%s for request[%s] to server[%s:%d] with rpc error %s", PolarisRequestTypeStr(request_type_),
951+
message_->ShortDebugString().c_str(), instance_->GetHost().c_str(), instance_->GetPort(),
952+
message.c_str());
953+
}else{
954+
POLARIS_LOG(LOG_ERROR, "%s for request[%s] to server[%s:%d] with rpc error %s", PolarisRequestTypeStr(request_type_),
955+
message_->ShortDebugString().c_str(), host_.c_str(), port_,
956+
message.c_str());
957+
}
958+
940959
server_code_ = kServerCodeRpcError;
941960
promise_->SetError(kReturnNetworkFailed);
942961
connector_.UpdateCallResult(this);

0 commit comments

Comments
 (0)