This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 61472fdb205 [fix](be) Guard RuntimeState access with task context
lifetime (#70691)
61472fdb205 is described below
commit 61472fdb205332b5fadaf924c591a653484028bc
Author: yiguolei <[email protected]>
AuthorDate: Wed Nov 18 09:14:33 2026 +0800
[fix](be) Guard RuntimeState access with task context lifetime (#70691)
### Background
Async result writer callbacks capture a weak task context and raw
pointers to RuntimeState and the writer. Pipeline task diagnostics also
access RuntimeState, whose lifetime is owned by the fragment.
---
be/src/exec/pipeline/pipeline_task.cpp | 5 +++--
be/src/exec/sink/writer/async_result_writer.cpp | 6 +++---
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/be/src/exec/pipeline/pipeline_task.cpp
b/be/src/exec/pipeline/pipeline_task.cpp
index d50af9e12b5..29e5a570754 100644
--- a/be/src/exec/pipeline/pipeline_task.cpp
+++ b/be/src/exec/pipeline/pipeline_task.cpp
@@ -968,8 +968,6 @@ std::string PipelineTask::debug_string() {
fmt::memory_buffer debug_string_buffer;
fmt::format_to(debug_string_buffer, "QueryId: {}\n", print_id(_query_id));
- fmt::format_to(debug_string_buffer, "InstanceId: {}\n",
- print_id(_state->fragment_instance_id()));
fmt::format_to(debug_string_buffer,
"PipelineTask[id = {}, open = {}, eos = {}, state = {}, dry
run = "
@@ -985,6 +983,9 @@ std::string PipelineTask::debug_string() {
fmt::format_to(debug_string_buffer, " pipeline name = {}",
_pipeline_name);
return fmt::to_string(debug_string_buffer);
}
+ // Access RuntimeState only while the fragment is kept alive.
+ fmt::format_to(debug_string_buffer, "\nInstanceId: {}\n",
+ print_id(_state->fragment_instance_id()));
auto elapsed = fragment->elapsed_time() / NANOS_PER_SEC;
fmt::format_to(debug_string_buffer, " elapse time = {}s, block dependency
= [{}]\n", elapsed,
cur_blocked_dep && !is_finalized() ?
cur_blocked_dep->debug_string() : "NULL");
diff --git a/be/src/exec/sink/writer/async_result_writer.cpp
b/be/src/exec/sink/writer/async_result_writer.cpp
index 84f9fe18ff5..9a254eb5b20 100644
--- a/be/src/exec/sink/writer/async_result_writer.cpp
+++ b/be/src/exec/sink/writer/async_result_writer.cpp
@@ -104,16 +104,16 @@ Status AsyncResultWriter::start_writer(RuntimeState*
state, RuntimeProfile* oper
// Should set to false here, to
DCHECK(_finish_dependency);
_finish_dependency->block();
- // This is a async thread, should lock the task ctx, to make sure
runtimestate and operator_profile
- // not deconstructed before the thread exit.
+ // Cancellation can destroy the fragment while this callback is queued.
Lock its context
+ // before attaching through the raw RuntimeState pointer or accessing
writer-owned state.
auto task_ctx = state->get_task_execution_context();
RETURN_IF_ERROR(ExecEnv::GetInstance()->fragment_mgr()->get_thread_pool()->submit_func(
[this, state, operator_profile, task_ctx]() {
- SCOPED_ATTACH_TASK(state);
auto task_lock = task_ctx.lock();
if (task_lock == nullptr) {
return;
}
+ SCOPED_ATTACH_TASK(state);
this->process_block(state, operator_profile);
task_lock.reset();
}));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]