github-actions[bot] commented on code in PR #62691:
URL: https://github.com/apache/doris/pull/62691#discussion_r3122238504
##########
be/src/runtime/memory/thread_mem_tracker_mgr.cpp:
##########
@@ -19,13 +19,32 @@
#include <gen_cpp/types.pb.h>
+#include "common/exception.h"
+#include "common/signal_handler.h"
#include "runtime/exec_env.h"
namespace doris {
void ThreadMemTrackerMgr::attach_limiter_tracker(
const std::shared_ptr<MemTrackerLimiter>& mem_tracker) {
DCHECK(mem_tracker);
+ if (UNLIKELY(!mem_tracker)) {
+ // Without this guard, _limiter_tracker silently becomes null and any
+ // later allocation on this thread would dereference it inside the
+ // allocator's memory check path, surfacing as a generic NPE far from
+ // the real call site that fed the null tracker. Embed the full
+ // ThreadMemTrackerMgr state (consumer stack, untracked_mem,
+ // reserved_mem) so the FATAL message alone is enough to triage. The
+ // query id is read from signal-handler thread-local storage; it
+ // does not depend on any object that may already be torn down.
+ throw Exception(Status::FatalError(
+ "ThreadMemTrackerMgr::attach_limiter_tracker called with null
mem_tracker. "
+ "previous limiter label={}, snapshot_stack_depth={}, "
+ "query_id={:x}-{:x}, mgr_state={{{}}}",
+ _limiter_tracker ? _limiter_tracker->label() : "<null>",
+ _last_attach_snapshots_stack.size(),
doris::signal::query_id_hi,
+ doris::signal::query_id_lo, print_debug_string()));
Review Comment:
Calling `print_debug_string()` here defeats the new diagnostic on the exact
`nullptr` case this branch is trying to catch. `attach_limiter_tracker()` does
this check before `CHECK(init())`, so on a fresh `ThreadMemTrackerMgr`
`_limiter_tracker` is still null. `print_debug_string()` unconditionally
dereferences `_limiter_tracker->make_profile_str()`, which means
`attach_limiter_tracker(nullptr)` will segfault while formatting the error
message instead of throwing the intended `FatalError`.
##########
be/src/runtime/thread_context.cpp:
##########
@@ -84,6 +161,16 @@ SwitchResourceContext::~SwitchResourceContext() {
SwitchThreadMemTrackerLimiter::SwitchThreadMemTrackerLimiter(
Review Comment:
`SwitchThreadMemTrackerLimiter` is not the only public entry point that can
feed a tracker into `attach_limiter_tracker()`. `AttachTask(const
std::shared_ptr<MemTrackerLimiter>&)` still does
`rc->memory_context()->set_mem_tracker(mem_tracker)` with no null check, and
`MemoryContext::set_mem_tracker()` dereferences `mem_tracker_->limit()`
immediately. So every existing `SCOPED_ATTACH_TASK(mem_tracker)` call site
still crashes before any of the new diagnostics run if a null tracker slips
through.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]