Skip to content

Commit a5a7877

Browse files
authored
Fixed the issue where the Crash Stace Trace of the C++ part was overwritten by the Golang stack when starting the Golang module. (#2171)
* fix crash trace * add ENTERPRISE switch * add ENTERPRISE switch * fix format * fix comments
1 parent da82e3e commit a5a7877

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

Diff for: core/application/Application.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void Application::Init() {
125125
AlarmManager::GetInstance()->SendAlarm(LOGTAIL_CRASH_STACK_ALARM, backTraceStr);
126126
}
127127
if (BOOL_FLAG(ilogtail_disable_core)) {
128-
InitCrashBackTrace();
128+
ResetCrashBackTrace();
129129
}
130130
#endif
131131
// override process related params if designated by user explicitly

Diff for: core/common/CrashBackTraceUtil.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ bool MinidumpCallbackFunc(const wchar_t* dump_path,
124124
}
125125
#endif
126126

127-
void InitCrashBackTrace() {
128-
#if defined(__ANDROID__)
129-
#elif defined(__linux__)
130-
g_crashBackTraceFilePtr = fopen((GetCrashStackFileName()).c_str(), "w");
127+
void ResetCrashBackTrace() {
128+
#if defined(__linux__)
131129
if (g_crashBackTraceFilePtr == NULL) {
132-
APSARA_LOG_ERROR(sLogger, ("unable to open stack back trace file", strerror(errno)));
133-
return;
130+
g_crashBackTraceFilePtr = fopen((GetCrashStackFileName()).c_str(), "w");
131+
if (g_crashBackTraceFilePtr == NULL) {
132+
APSARA_LOG_ERROR(sLogger, ("unable to open stack back trace file", strerror(errno)));
133+
return;
134+
}
134135
}
135136
signal(SIGSEGV, CrashBackTrace); // SIGSEGV 11 Core Invalid memory reference
136137
signal(SIGABRT, CrashBackTrace); // SIGABRT 6 Core Abort signal from
@@ -140,9 +141,11 @@ void InitCrashBackTrace() {
140141
_mkdir("dumps");
141142
g_handler.reset(new google_breakpad::ExceptionHandler(
142143
L"dumps\\", FilterCallbackFunc, MinidumpCallbackFunc, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL));
144+
#elif defined(__ANDROID__)
143145
#endif
144146
}
145147

148+
146149
std::string GetCrashBackTrace() {
147150
auto stackFilePath = GetCrashStackFileName();
148151
FILE* pStackFile = fopen(stackFilePath.c_str(), "rb");

Diff for: core/common/CrashBackTraceUtil.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
namespace logtail {
2121

22-
void InitCrashBackTrace();
23-
22+
void ResetCrashBackTrace();
2423
std::string GetCrashBackTrace();
2524

2625
} // namespace logtail

Diff for: core/go_pipeline/LogtailPlugin.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "app_config/AppConfig.h"
2020
#include "collection_pipeline/CollectionPipelineManager.h"
2121
#include "collection_pipeline/queue/SenderQueueManager.h"
22+
#include "common/CrashBackTraceUtil.h"
2223
#include "common/DynamicLibHelper.h"
2324
#include "common/HashUtil.h"
2425
#include "common/JsonUtil.h"
@@ -39,6 +40,7 @@ DEFINE_FLAG_BOOL(enable_sls_metrics_format, "if enable format metrics in SLS met
3940
DECLARE_FLAG_STRING(ALIYUN_LOG_FILE_TAGS);
4041
DECLARE_FLAG_INT32(file_tags_update_interval);
4142
DECLARE_FLAG_STRING(agent_host_id);
43+
DECLARE_FLAG_BOOL(ilogtail_disable_core);
4244

4345
using namespace std;
4446
using namespace logtail;
@@ -477,6 +479,11 @@ bool LogtailPlugin::LoadPluginBase() {
477479
} else {
478480
LOG_INFO(sLogger, ("Go plugin system init", "succeeded"));
479481
mPluginValid = true;
482+
#ifdef __ENTERPRISE__
483+
if (BOOL_FLAG(ilogtail_disable_core)) {
484+
ResetCrashBackTrace();
485+
}
486+
#endif
480487
}
481488
return mPluginValid;
482489
}

0 commit comments

Comments
 (0)