diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 777e4f824040f675d026f0785217f2b47f669105..348f4bda9a0d144219475a9b5855a6ecf3b8a485 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -1114,10 +1114,13 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) { if (pHead->code == TSDB_CODE_RPC_REDIRECT) { pContext->numOfTry = 0; - memcpy(&pContext->epSet, pHead->content, sizeof(pContext->epSet)); - tDebug("%s, redirect is received, numOfEps:%d", pConn->info, pContext->epSet.numOfEps); - for (int i=0; iepSet.numOfEps; ++i) - pContext->epSet.port[i] = htons(pContext->epSet.port[i]); + SRpcEpSet *pEpSet = (SRpcEpSet*)pHead->content; + if (pEpSet->numOfEps > 0) { + memcpy(&pContext->epSet, pHead->content, sizeof(pContext->epSet)); + tDebug("%s, redirect is received, numOfEps:%d", pConn->info, pContext->epSet.numOfEps); + for (int i=0; iepSet.numOfEps; ++i) + pContext->epSet.port[i] = htons(pContext->epSet.port[i]); + } rpcSendReqToServer(pRpc, pContext); rpcFreeCont(rpcMsg.pCont); } else if (pHead->code == TSDB_CODE_RPC_NOT_READY || pHead->code == TSDB_CODE_APP_NOT_READY) { diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index f4778f50cee5597730254689edee4453adedf639..61896a86dfb51e997f5c296706f869460dd390e3 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -19,26 +19,25 @@ #include "tutil.h" int taosGetFqdn(char *fqdn) { - int code = 0; char hostname[1024]; hostname[1023] = '\0'; - gethostname(hostname, 1023); + if (gethostname(hostname, 1023) == -1) { + uError("failed to get hostname, reason:%s", strerror(errno)); + return -1; + } struct addrinfo hints = {0}; struct addrinfo *result = NULL; - hints.ai_flags = AI_CANONNAME; - - int32_t ret = getaddrinfo(hostname, NULL, &hints, &result); - if (result) { - strcpy(fqdn, result->ai_canonname); - freeaddrinfo(result); - } else { + int ret = getaddrinfo(hostname, NULL, &hints, &result); + if (!result) { uError("failed to get fqdn, code:%d, reason:%s", ret, gai_strerror(ret)); - code = -1; + return -1; } - return code; + strcpy(fqdn, result->ai_canonname); + freeaddrinfo(result); + return 0; } uint32_t taosGetIpFromFqdn(const char *fqdn) {