fix crash while process transmsg

This commit is contained in:
Shengliang Guan 2022-01-04 18:27:11 -08:00
parent c0aded7b57
commit 6ae9a421e0
5 changed files with 44 additions and 32 deletions

View File

@ -306,14 +306,16 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
} }
dndReleaseQnode(pDnode, pQnode); dndReleaseQnode(pDnode, pQnode);
if (pRsp != NULL) { if (pMsg->msgType & 1u) {
pRsp->ahandle = pMsg->ahandle; if (pRsp != NULL) {
rpcSendResponse(pRsp); pRsp->ahandle = pMsg->ahandle;
free(pRsp); rpcSendResponse(pRsp);
} else { free(pRsp);
if (code != 0) code = terrno; } else {
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; if (code != 0) code = terrno;
rpcSendResponse(&rpcRsp); SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
rpcSendResponse(&rpcRsp);
}
} }
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);

View File

@ -300,14 +300,16 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
} }
dndReleaseSnode(pDnode, pSnode); dndReleaseSnode(pDnode, pSnode);
if (pRsp != NULL) { if (pMsg->msgType & 1u) {
pRsp->ahandle = pMsg->ahandle; if (pRsp != NULL) {
rpcSendResponse(pRsp); pRsp->ahandle = pMsg->ahandle;
free(pRsp); rpcSendResponse(pRsp);
} else { free(pRsp);
if (code != 0) code = terrno; } else {
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; if (code != 0) code = terrno;
rpcSendResponse(&rpcRsp); SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
rpcSendResponse(&rpcRsp);
}
} }
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);

View File

@ -366,14 +366,16 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
return NULL; return NULL;
} }
SRpcConnInfo connInfo = {0}; if (pRpcMsg->msgType != TDMT_MND_TRANS) {
if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { SRpcConnInfo connInfo = {0};
taosFreeQitem(pMsg); if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; taosFreeQitem(pMsg);
mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
return NULL; mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle);
return NULL;
}
memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN);
} }
memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN);
pMsg->pMnode = pMnode; pMsg->pMnode = pMnode;
pMsg->rpcMsg = *pRpcMsg; pMsg->rpcMsg = *pRpcMsg;

View File

@ -50,7 +50,18 @@ TEST_F(MndTestQnode, 01_Show_Qnode) {
EXPECT_EQ(test.GetShowRows(), 0); EXPECT_EQ(test.GetShowRows(), 0);
} }
TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { TEST_F(MndTestQnode, 02_Create_Qnode) {
{
int32_t contLen = sizeof(SMCreateQnodeReq);
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
}
{ {
int32_t contLen = sizeof(SMCreateQnodeReq); int32_t contLen = sizeof(SMCreateQnodeReq);
@ -63,11 +74,6 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) {
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
CHECK_META("show qnodes", 3); CHECK_META("show qnodes", 3);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
test.SendShowRetrieveMsg(); test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
@ -75,14 +81,12 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) {
CheckBinary("localhost:9014", TSDB_EP_LEN); CheckBinary("localhost:9014", TSDB_EP_LEN);
CheckTimestamp(); CheckTimestamp();
} }
}
TEST_F(MndTestQnode, 03_Create_Qnode_Invalid_Id) {
{ {
int32_t contLen = sizeof(SMCreateQnodeReq); int32_t contLen = sizeof(SMCreateQnodeReq);
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2); pReq->dnodeId = htonl(1);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pMsg, nullptr);

View File

@ -423,6 +423,8 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t
} }
void rpcSendResponse(const SRpcMsg *pRsp) { void rpcSendResponse(const SRpcMsg *pRsp) {
if (pRsp->handle == NULL) return;
int msgLen = 0; int msgLen = 0;
SRpcConn *pConn = (SRpcConn *)pRsp->handle; SRpcConn *pConn = (SRpcConn *)pRsp->handle;
SRpcMsg rpcMsg = *pRsp; SRpcMsg rpcMsg = *pRsp;