From 852f5b6fa45f0157744c124ba0cf71d4dc7461e7 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Thu, 9 Jan 2025 16:02:11 +0800 Subject: [PATCH] fix: write crash log --- source/client/src/clientEnv.c | 12 ++++++------ source/common/src/tmisce.c | 3 ++- source/util/src/tlog.c | 15 +++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 41968d8155..c22bae3fbf 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -815,12 +815,6 @@ static void *tscCrashReportThreadFp(void *param) { int32_t reportPeriodNum = 3600 * 1000 / sleepTime; int32_t loopTimes = reportPeriodNum; - code = initCrashLogWriter(); - if (code) { - tscError("failed to init crash log writer, code:%s", tstrerror(code)); - return NULL; - } - #ifdef WINDOWS if (taosCheckCurrentInDll()) { atexit(crashReportThreadFuncUnexpectedStopped); @@ -837,6 +831,12 @@ static void *tscCrashReportThreadFp(void *param) { return NULL; } + code = initCrashLogWriter(); + if (code) { + tscError("failed to init crash log writer, code:%s", tstrerror(code)); + return NULL; + } + while (1) { checkAndPrepareCrashInfo(); if (clientStop > 0) break; diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c index 144a1542cb..a966513629 100644 --- a/source/common/src/tmisce.c +++ b/source/common/src/tmisce.c @@ -231,6 +231,7 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashSig", signum), NULL, _exit); TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashTs", taosGetTimestampUs()), NULL, _exit); +#if 0 #ifdef _TD_DARWIN_64 taosLogTraceToBuf(tmp, sizeof(tmp), 4); #elif !defined(WINDOWS) @@ -240,7 +241,7 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t #endif TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "stackInfo", tmp), NULL, _exit); - +#endif char* pCont = tjsonToString(pJson); if (pCont == NULL) { code = terrno; diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 5251076fa5..a06b6c0746 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -1317,29 +1317,28 @@ void checkAndPrepareCrashInfo() { } int32_t initCrashLogWriter() { - gCrashBasicInfo.init = true; - gCrashBasicInfo.isCrash = false; int32_t code = tsem_init(&gCrashBasicInfo.sem, 0, 0); - uInfo("crashLogWriter init finished."); + if (code != 0) { + uError("failed to init sem for crashLogWriter, code:%d", code); + return code; + } + gCrashBasicInfo.isCrash = false; + gCrashBasicInfo.init = true; return code; } void writeCrashLogToFile(int signum, void *sigInfo, char *nodeType, int64_t clusterId, int64_t startTime) { if (!gCrashBasicInfo.init) { - uInfo("crashLogWriter has not init!"); return; } - uInfo("write crash log to file, signum:%d, nodeType:%s, clusterId:%" PRId64, signum, nodeType, clusterId); - gCrashBasicInfo.isCrash = true; gCrashBasicInfo.clusterId = clusterId; gCrashBasicInfo.startTime = startTime; gCrashBasicInfo.nodeType = nodeType; gCrashBasicInfo.signum = signum; gCrashBasicInfo.sigInfo = sigInfo; + gCrashBasicInfo.isCrash = true; tsem_wait(&gCrashBasicInfo.sem); - - uInfo("write crash log to file done, signum:%d, nodeType:%s, clusterId:%" PRId64, signum, nodeType, clusterId); } void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd) {