Merge pull request #28939 from taosdata/fixx/TD-33005-3.0

handle random memory failure
This commit is contained in:
Hongze Cheng 2024-11-27 09:02:08 +08:00 committed by GitHub
commit 6e6386eed1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 14 deletions

View File

@ -1816,7 +1816,7 @@ int32_t doProcessMsgFromServerImpl(SRpcMsg* pMsg, SEpSet* pEpSet) {
.handleRefId = pMsg->info.refId, .handleRefId = pMsg->info.refId,
.pEpSet = pEpSet}; .pEpSet = pEpSet};
if (pMsg->contLen > 0) { if (pMsg->code != TSDB_CODE_OUT_OF_MEMORY && pMsg->contLen > 0) {
buf.pData = taosMemoryCalloc(1, pMsg->contLen); buf.pData = taosMemoryCalloc(1, pMsg->contLen);
if (buf.pData == NULL) { if (buf.pData == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
@ -2400,8 +2400,8 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, bool convertUcs4) {
p += sizeof(int32_t); p += sizeof(int32_t);
if (rows != pResultInfo->numOfRows || cols != pResultInfo->numOfCols) { if (rows != pResultInfo->numOfRows || cols != pResultInfo->numOfCols) {
tscError("setResultDataPtr paras error:rows;%d numOfRows:%" PRId64 " cols:%d numOfCols:%d", rows, pResultInfo->numOfRows, cols, tscError("setResultDataPtr paras error:rows;%d numOfRows:%" PRId64 " cols:%d numOfCols:%d", rows,
pResultInfo->numOfCols); pResultInfo->numOfRows, cols, pResultInfo->numOfCols);
return TSDB_CODE_TSC_INTERNAL_ERROR; return TSDB_CODE_TSC_INTERNAL_ERROR;
} }
@ -2577,8 +2577,7 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableR
// TODO handle the compressed case // TODO handle the compressed case
pResultInfo->totalRows += pResultInfo->numOfRows; pResultInfo->totalRows += pResultInfo->numOfRows;
int32_t code = int32_t code = setResultDataPtr(pResultInfo, convertUcs4);
setResultDataPtr(pResultInfo, convertUcs4);
return code; return code;
} }

View File

@ -2017,7 +2017,9 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) {
tWarn("%s conn %p failed to added to heap cache since %s", pInst->label, pConn, tstrerror(code)); tWarn("%s conn %p failed to added to heap cache since %s", pInst->label, pConn, tstrerror(code));
} }
} else { } else {
// TAOS_CHECK_GOTO(code, &lino, _exception); if (code == TSDB_CODE_OUT_OF_MEMORY && pConn == NULL) {
TAOS_CHECK_GOTO(code, &lino, _exception);
}
return; return;
} }
} }
@ -2496,10 +2498,6 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) {
_end: _end:
if (pThrd) { if (pThrd) {
TAOS_UNUSED(taosThreadMutexDestroy(&pThrd->msgMtx)); TAOS_UNUSED(taosThreadMutexDestroy(&pThrd->msgMtx));
TAOS_UNUSED(uv_loop_close(pThrd->loop));
taosMemoryFree(pThrd->loop);
TAOS_UNUSED((taosThreadMutexDestroy(&pThrd->msgMtx)));
transAsyncPoolDestroy(pThrd->asyncPool); transAsyncPoolDestroy(pThrd->asyncPool);
for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) {
uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i);
@ -2509,6 +2507,9 @@ _end:
taosArrayDestroy(pThrd->timerList); taosArrayDestroy(pThrd->timerList);
TAOS_UNUSED(destroyConnPool(pThrd)); TAOS_UNUSED(destroyConnPool(pThrd));
TAOS_UNUSED(uv_loop_close(pThrd->loop));
taosMemoryFree(pThrd->loop);
transDQDestroy(pThrd->delayQueue, NULL); transDQDestroy(pThrd->delayQueue, NULL);
transDQDestroy(pThrd->timeoutQueue, NULL); transDQDestroy(pThrd->timeoutQueue, NULL);
transDQDestroy(pThrd->waitConnQueue, NULL); transDQDestroy(pThrd->waitConnQueue, NULL);

View File

@ -1320,8 +1320,6 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) {
TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, &lino, _end); TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, &lino, _end);
} }
QUEUE_INIT(&exh->q);
SExHandle* pSelf = transAcquireExHandle(uvGetConnRefOfThrd(pThrd), exh->refId); SExHandle* pSelf = transAcquireExHandle(uvGetConnRefOfThrd(pThrd), exh->refId);
if (pSelf != exh) { if (pSelf != exh) {
TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end); TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end);
@ -1369,6 +1367,12 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) {
return pConn; return pConn;
_end: _end:
if (pConn) { if (pConn) {
if (pConn->refId > 0) {
transReleaseExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId);
transRemoveExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId);
pConn->refId = -1;
}
transQueueDestroy(&pConn->resps); transQueueDestroy(&pConn->resps);
transDestroyBuffer(&pConn->readBuf); transDestroyBuffer(&pConn->readBuf);
taosHashCleanup(pConn->pQTable); taosHashCleanup(pConn->pQTable);
@ -1378,7 +1382,7 @@ _end:
taosMemoryFree(pConn); taosMemoryFree(pConn);
pConn = NULL; pConn = NULL;
} }
tError("%s failed to create conn since %s" PRId64, transLabel(pInst), tstrerror(code)); tError("%s failed to create conn since %s", transLabel(pInst), tstrerror(code));
return NULL; return NULL;
} }