From 70e7a9f21fa1405a6d0912a5397734ec2a31897e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 10 Jun 2020 11:41:01 +0800 Subject: [PATCH 1/2] [td-225] add error output for getaddrinfo --- src/rpc/src/rpcMain.c | 2 +- src/util/src/tsocket.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index b0a5a0bfc0..6a45b10693 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -493,7 +493,7 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort, SRpcConn *pConn; uint32_t peerIp = taosGetIpFromFqdn(peerFqdn); - if (peerIp == -1) { + if (peerIp == 0xFFFFFFFF) { tError("%s, failed to resolve FQDN:%s", pRpc->label, peerFqdn); terrno = TSDB_CODE_RPC_APP_ERROR; return NULL; diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 00c8bba94e..4ff73807e8 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -44,7 +44,7 @@ uint32_t taosGetIpFromFqdn(const char *fqdn) { struct addrinfo hints = {0}; struct addrinfo *result = NULL; - getaddrinfo(fqdn, NULL, &hints, &result); + int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result); if (result) { struct sockaddr *sa = result->ai_addr; struct sockaddr_in *si = (struct sockaddr_in*)sa; @@ -53,7 +53,8 @@ uint32_t taosGetIpFromFqdn(const char *fqdn) { freeaddrinfo(result); return ip; } else { - return -1; + uError("failed get the addr info, code:%d, reason:%s", ret, gai_strerror(ret)); + return 0xFFFFFFFF; } } From 97d2f1e425babb944fb161959eb15b59a1b495a3 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 10 Jun 2020 12:12:23 +0800 Subject: [PATCH 2/2] [td-225] add error log for socket --- src/util/src/tsocket.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 4ff73807e8..1f4d57115b 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -29,11 +29,12 @@ int taosGetFqdn(char *fqdn) { hints.ai_flags = AI_CANONNAME; - getaddrinfo(hostname, NULL, &hints, &result); + int32_t ret = getaddrinfo(hostname, NULL, &hints, &result); if (result) { strcpy(fqdn, result->ai_canonname); freeaddrinfo(result); } else { + uError("failed to get fqdn, code:%d, reason:%s", ret, gai_strerror(ret)); code = -1; } @@ -42,6 +43,9 @@ int taosGetFqdn(char *fqdn) { uint32_t taosGetIpFromFqdn(const char *fqdn) { struct addrinfo hints = {0}; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + struct addrinfo *result = NULL; int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result); @@ -53,7 +57,7 @@ uint32_t taosGetIpFromFqdn(const char *fqdn) { freeaddrinfo(result); return ip; } else { - uError("failed get the addr info, code:%d, reason:%s", ret, gai_strerror(ret)); + uError("failed get the ip address, fqdn:%s, code:%d, reason:%s", fqdn, ret, gai_strerror(ret)); return 0xFFFFFFFF; } }