Skip to content

Commit 4eb6d7b

Browse files
authored
fix(server): Fix AllocatingTracker crash due to VLOG (#5827)
1 parent 654a8eb commit 4eb6d7b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/core/allocation_tracker.cc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ namespace dfly {
1212
namespace {
1313
thread_local AllocationTracker g_tracker;
1414
thread_local absl::InsecureBitGen g_bitgen;
15+
16+
bool CanCallVlog(std::string_view trace) {
17+
// GLOG fails when logging while flushing the current log under a mutex
18+
return trace.find("LogMessage::Flush") == std::string::npos;
19+
}
20+
1521
} // namespace
1622

1723
AllocationTracker& AllocationTracker::Get() {
@@ -75,9 +81,13 @@ void AllocationTracker::ProcessNew(void* ptr, size_t size) {
7581
}
7682

7783
size_t usable = mi_usable_size(ptr);
78-
DCHECK_GE(usable, size);
79-
LOG(INFO) << "Allocating " << usable << " bytes (" << ptr
80-
<< "). Stack: " << util::fb2::GetStacktrace();
84+
std::string trace = util::fb2::GetStacktrace();
85+
86+
if (CanCallVlog(trace)) {
87+
DCHECK_GE(usable, size);
88+
LOG(INFO) << "Allocating " << usable << " bytes (" << ptr << "). Stack: " << trace;
89+
}
90+
8191
break;
8292
}
8393
inside_tracker_ = false;
@@ -94,8 +104,9 @@ void AllocationTracker::ProcessDelete(void* ptr) {
94104
if (tracking_.size() == 1 && tracking_.front().sample_odds == 1) {
95105
size_t usable = mi_usable_size(ptr);
96106
if (usable <= tracking_.front().upper_bound && usable >= tracking_.front().lower_bound) {
97-
LOG(INFO) << "Deallocating " << usable << " bytes (" << ptr << ")\n"
98-
<< util::fb2::GetStacktrace();
107+
std::string trace = util::fb2::GetStacktrace();
108+
LOG_IF(INFO, CanCallVlog(trace)) << "Deallocating " << usable << " bytes (" << ptr << ")\n"
109+
<< trace;
99110
}
100111
}
101112
inside_tracker_ = false;

0 commit comments

Comments
 (0)