github-actions[bot] commented on code in PR #62691:
URL: https://github.com/apache/doris/pull/62691#discussion_r3121433945


##########
be/src/runtime/thread_context.h:
##########
@@ -168,6 +168,25 @@ class ThreadContext {
     void attach_task(const std::shared_ptr<ResourceContext>& rc) {
         // will only attach_task at the beginning of the thread function, 
there should be no duplicate attach_task.
         DCHECK(resource_ctx_ == nullptr);
+        // Disambiguate which sub-object is null when attach silently 
propagates a null
+        // mem_tracker (see attach_limiter_tracker). These checks tell us at 
the source
+        // whether `rc` itself is empty, the embedded MemoryContext is null, 
or the
+        // MemoryContext exists but its mem_tracker_ was never set
+        // (i.e. _init_query_mem_tracker hasn't run yet for this 
ResourceContext).
+        if (UNLIKELY(rc == nullptr)) {

Review Comment:
   Blocking: these throws happen only after `AttachTask::init()` has already 
called `ThreadLocalHandle::create_thread_local_if_not_exits()` and 
`signal::set_signal_task_id(rc->task_controller()->task_id())` in 
`thread_context.cpp`. If one of the new checks fires, construction aborts 
before `~AttachTask()` runs, so the worker leaks `thread_local_handle_count` 
and keeps a stale signal task id. Also, the `rc == nullptr` case still 
dereferences `rc` earlier in `AttachTask::init()`, so this branch does not 
actually diagnose that path. The validation needs to happen before the TLS / 
signal mutation, or `init()` needs rollback on exception.



##########
be/src/exec/pipeline/pipeline_task.cpp:
##########
@@ -507,6 +508,16 @@ Status PipelineTask::execute(bool* done) {
         // called. This relies on _wake_up_early and _always_ready both being 
std::atomic with the
         // default seq_cst ordering — do not weaken them to relaxed or acq/rel.
         if (_wake_up_early) {
+            // Sanity-check the pointers we are about to dereference so the 
failure
+            // mode tells us *which* pointer is null instead of an opaque NPE 
inside
+            // the operator's terminate() call. Also dump the query_id for 
triage.

Review Comment:
   Blocking: this does not actually give a stable error for the null cases. 
`_do_work()` catches the exception from `execute()`, but its cleanup path 
always runs `close_task(task.get(), status, ...)`. That immediately does 
`SCOPED_ATTACH_TASK(task->runtime_state())` and then `task->close()`. So if 
`_state` is null we now throw again from `close_task()` with no catch in the 
worker thread, and if `_sink` is null `PipelineTask::close()` still 
dereferences it. The scheduler / close path has to be made null-safe before 
this branch can safely replace the original NPE.



##########
be/src/runtime/memory/thread_mem_tracker_mgr.cpp:
##########
@@ -54,7 +65,25 @@ void ThreadMemTrackerMgr::detach_limiter_tracker() {
     CHECK(init());
     flush_untracked_mem();
     shrink_reserved();

Review Comment:
   Blocking: `detach_limiter_tracker()` is the teardown path for 
`~AttachTask()`, `~SwitchResourceContext()`, and 
`~SwitchThreadMemTrackerLimiter()`. Those destructors are implicitly 
`noexcept`, so these new `throw Exception(...)` branches will call 
`std::terminate` before any outer `ASSIGN_STATUS_IF_CATCH_EXCEPTION` / RPC 
handler can translate the error. Before this patch the release build only had 
the existing `DCHECK`; after this patch an unbalanced attach/detach becomes an 
unconditional process abort from RAII cleanup. If this invariant is meant to be 
fatal, it needs a non-throwing fatal path here, not an exception from 
destructor-backed cleanup.



##########
be/src/runtime/memory/thread_mem_tracker_mgr.h:
##########
@@ -101,6 +102,15 @@ class ThreadMemTrackerMgr {
 
     MemTrackerLimiter* limiter_mem_tracker() {
         CHECK(init());

Review Comment:
   Blocking: `limiter_mem_tracker()` is called from `core/allocator.cpp` on the 
allocator / memory-hook path (`sys_memory_exceed()`, `memory_tracker_exceed()`, 
ASAN helpers, etc.). Building `Status::FatalError` + `Exception` here allocates 
strings, gathers a stack trace, and logs exactly when `_limiter_tracker` is 
already poisoned. Those allocations re-enter the Doris allocator / memory hook, 
so this diagnostic path can recurse or crash before it ever returns a clean 
message. This needs an allocation-free failure path (or earlier validation 
before we reach allocator code), not a normal exception object.



-- 
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]

Reply via email to