From d0809d6adfc4374e83ed62eaa6c89b117a5f27d6 Mon Sep 17 00:00:00 2001 From: Guohao Li Date: Tue, 30 Jan 2024 13:53:58 +0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Dan Wang --- src/runtime/rpc/rpc_address.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runtime/rpc/rpc_address.cpp b/src/runtime/rpc/rpc_address.cpp index d547fc1a2c..8d98b17809 100644 --- a/src/runtime/rpc/rpc_address.cpp +++ b/src/runtime/rpc/rpc_address.cpp @@ -52,11 +52,12 @@ error_s rpc_address::GetAddrInfo(const std::string &hostname, const addrinfo &hi const int rc = getaddrinfo(hostname.c_str(), nullptr, &hints, &res); const int err = errno; // preserving the errno from the getaddrinfo() call AddrInfo result(res, ::freeaddrinfo); - if (rc != 0) { + if (dsn_unlikely(rc != 0)) { if (rc == EAI_SYSTEM) { + const auto &err_msg = utils::safe_strerror(err); LOG_ERROR( - "getaddrinfo failed, name = {}, err = {}", hostname, utils::safe_strerror(rc)); - return error_s::make(ERR_NETWORK_FAILURE, utils::safe_strerror(err)); + "getaddrinfo failed, name = {}, err = {}", hostname, err_msg); + return error_s::make(ERR_NETWORK_FAILURE, err_msg); } LOG_ERROR("getaddrinfo failed, name = {}, err = {}", hostname, gai_strerror(rc)); return error_s::make(ERR_NETWORK_FAILURE, gai_strerror(rc));