From 7ad701cc5e48681226cccecf4760f5a306c836ca Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 10:37:39 +0800 Subject: [PATCH] [td-11818] add rsp error check. --- source/client/src/clientMsgHandler.c | 53 ++++++++++++++++++---------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index f4cec5c627..9ee890afd9 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -22,19 +22,23 @@ int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); +static void setErrno(SRequestObj* pRequest, int32_t code) { + pRequest->code = code; + terrno = code; +} + int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; - pRequest->code = code; + setErrno(pRequest, code); + sem_post(&pRequest->body.rspSem); - return 0; + return code; } int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - terrno = code; - + setErrno(pRequest, code); sem_post(&pRequest->body.rspSem); return code; } @@ -115,7 +119,7 @@ SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) { int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; + setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; } @@ -157,19 +161,18 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { } int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) { - assert(pMsg->len >= sizeof(SRetrieveTableRsp)); - - SRequestObj* pRequest = param; - SReqResultInfo* pResInfo = &pRequest->body.resInfo; - + SRequestObj *pRequest = param; + SReqResultInfo *pResInfo = &pRequest->body.resInfo; tfree(pResInfo->pRspMsg); + if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - terrno = code; + setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; } + assert(pMsg->len >= sizeof(SRetrieveTableRsp)); + SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg->pData; pRetrieve->numOfRows = htonl(pRetrieve->numOfRows); pRetrieve->precision = htons(pRetrieve->precision); @@ -195,8 +198,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { tfree(pRequest->body.resInfo.pRspMsg); if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - terrno = code; + setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; } @@ -209,7 +211,6 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { SReqResultInfo* pResInfo = &pRequest->body.resInfo; - tfree(pResInfo->pRspMsg); pResInfo->pRspMsg = pMsg->pData; pResInfo->numOfRows = pFetchRsp->numOfRows; pResInfo->pData = pFetchRsp->data; @@ -231,6 +232,14 @@ int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { } int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj* pRequest = param; + + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg->pData; SName name = {0}; tNameFromString(&name, pUseDbRsp->db, T_NAME_ACCT|T_NAME_DB); @@ -238,17 +247,23 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { char db[TSDB_DB_NAME_LEN] = {0}; tNameGetDbName(&name, db); - SRequestObj* pRequest = param; setConnectionDB(pRequest->pTscObj, db); - tsem_post(&pRequest->body.rspSem); return 0; } int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { - assert(pMsg != NULL); + assert(pMsg != NULL && param != NULL); SRequestObj* pRequest = param; + + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + tsem_post(&pRequest->body.rspSem); + return code; } int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {