diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 4bb29f8d97..10e6695ee5 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -120,9 +120,13 @@ static int32_t monitorReportAsyncCB(void* param, SDataBuf* pMsg, int32_t code) { .data = NULL}; if (monitorPutData2MonitorQueue(tmp) == 0) { p->fileName = NULL; + } else { + if(taosCloseFile(&(p->pFile)) != 0) { + tscError("failed to close file:%p", p->pFile); + } } } - return code; + return TSDB_CODE_SUCCESS; } static int32_t sendReport(void* pTransporter, SEpSet* epSet, char* pCont, MONITOR_TYPE type, void* param) { @@ -164,7 +168,10 @@ static int32_t sendReport(void* pTransporter, SEpSet* epSet, char* pCont, MONITO int64_t transporterId = 0; return asyncSendMsgToServer(pTransporter, epSet, &transporterId, pInfo); - FAILED: +FAILED: + if (taosCloseFile(&(((MonitorSlowLogData*)param)->pFile)) != 0) { + tscError("failed to close file:%p", ((MonitorSlowLogData*)param)->pFile); + } monitorFreeSlowLogDataEx(param); return TAOS_GET_TERRNO(TSDB_CODE_TSC_INTERNAL_ERROR); } @@ -315,7 +322,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* void monitorCounterInc(int64_t clusterId, const char* counterName, const char** label_values) { taosWLockLatch(&monitorLock); if (atomic_load_32(&monitorFlag) == 1) { - taosRUnLockLatch(&monitorLock); + taosWUnLockLatch(&monitorLock); return; } @@ -462,11 +469,17 @@ static int64_t getFileSize(char* path) { static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64_t offset, SLOW_LOG_QUEUE_TYPE type, char* fileName, void* pTransporter, SEpSet* epSet) { if (data == NULL) { + if (taosCloseFile(&pFile) != 0) { + tscError("failed to close file:%p", pFile); + } taosMemoryFree(fileName); return TSDB_CODE_INVALID_PARA; } MonitorSlowLogData* pParam = taosMemoryMalloc(sizeof(MonitorSlowLogData)); if (pParam == NULL) { + if (taosCloseFile(&pFile) != 0) { + tscError("failed to close file:%p", pFile); + } taosMemoryFree(data); taosMemoryFree(fileName); return terrno; @@ -485,6 +498,9 @@ static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offs SAppInstInfo* pInst = getAppInstByClusterId(clusterId); if (pInst == NULL) { tscError("failed to get app instance by clusterId:%" PRId64, clusterId); + if (taosCloseFile(&pFile) != 0) { + tscError("failed to close file:%p", pFile); + } taosMemoryFree(fileName); return terrno; } @@ -710,7 +726,7 @@ static void* monitorThreadFunc(void* param) { MonitorSlowLogData* slowLogData = NULL; (void)taosReadQitem(monitorQueue, (void**)&slowLogData); if (slowLogData != NULL) { - if (slowLogData->type == SLOW_LOG_READ_BEGINNIG) { + if (slowLogData->type == SLOW_LOG_READ_BEGINNIG && quitCnt == 0) { if (slowLogData->pFile != NULL) { monitorSendSlowLogAtBeginning(slowLogData->clusterId, &(slowLogData->fileName), slowLogData->pFile, slowLogData->offset); @@ -729,9 +745,9 @@ static void* monitorThreadFunc(void* param) { break; } } + monitorFreeSlowLogData(slowLogData); + taosFreeQitem(slowLogData); } - monitorFreeSlowLogData(slowLogData); - taosFreeQitem(slowLogData); if (quitCnt == 0) { monitorSendAllSlowLog(); @@ -853,6 +869,9 @@ int32_t monitorPutData2MonitorQueue(MonitorSlowLogData data) { if (taosWriteQitem(monitorQueue, slowLogData) == 0) { (void)tsem2_post(&monitorSem); } else { + if (taosCloseFile(&(slowLogData->pFile)) != 0) { + tscError("failed to close file:%p", slowLogData->pFile); + } monitorFreeSlowLogData(slowLogData); taosFreeQitem(slowLogData); }