You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by pa...@apache.org on 2026/04/08 08:05:55 UTC
(doris) branch master updated: [fix](pipeline) Prevent wake_up() from submitting finalized task to scheduler (#62155)
This is an automated email from the ASF dual-hosted git repository.
panxiaolei 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 6ea8fa5d44e [fix](pipeline) Prevent wake_up() from submitting finalized task to scheduler (#62155)
6ea8fa5d44e is described below
commit 6ea8fa5d44e7d37dd1dbd372031355f8f1ab5e39
Author: Pxl <xl...@selectdb.com>
AuthorDate: Wed Apr 8 16:05:47 2026 +0800
[fix](pipeline) Prevent wake_up() from submitting finalized task to scheduler (#62155)
This pull request addresses a race condition in the pipeline task state
machine that could cause a terminated task to be incorrectly
resubmitted, potentially leading to a segmentation fault. It also
improves test coverage to ensure correct scheduler behavior and adds
instrumentation for better test assertions.
**Bug fix and state transition safety:**
* Prevents resubmission of terminated (`FINISHED` or `FINALIZED`)
pipeline tasks in `PipelineTask::wake_up`, avoiding potential SIGSEGV
crashes by ensuring tasks are not resubmitted after finalization.
* Updates the state transition logic in `_state_transition` to avoid
updating the task profile or moving the state backwards for terminated
tasks, ensuring accurate profiling and state management.
**Test and instrumentation improvements:**
* Enhances the `MockTaskScheduler` with a submit counter and reset
functionality, allowing tests to verify how many times tasks are
submitted.
[[1]](diffhunk://#diff-0609833b9011bb33567e5026830b533b84096c8d698e5fc8f212fbfaf22a3f29L56-R59)
[[2]](diffhunk://#diff-0609833b9011bb33567e5026830b533b84096c8d698e5fc8f212fbfaf22a3f29R69-R74)
* Extends the `PipelineTaskTest.TEST_STATE_TRANSITION` test to assert
that terminated tasks are not resubmitted and that only valid state
transitions result in scheduler submissions.
---------
Co-authored-by: Copilot <22...@users.noreply.github.com>
---
be/src/exec/pipeline/pipeline_task.cpp | 23 ++++++++++++++++-------
be/test/exec/pipeline/dummy_task_queue.h | 9 ++++++++-
be/test/exec/pipeline/pipeline_task_test.cpp | 19 ++++++++++++++++++-
3 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/be/src/exec/pipeline/pipeline_task.cpp b/be/src/exec/pipeline/pipeline_task.cpp
index 0e98c8a2643..f33944ea4f8 100644
--- a/be/src/exec/pipeline/pipeline_task.cpp
+++ b/be/src/exec/pipeline/pipeline_task.cpp
@@ -1050,6 +1050,13 @@ Status PipelineTask::wake_up(Dependency* dep, std::unique_lock<std::mutex>& /* d
_blocked_dep = nullptr;
auto holder = std::dynamic_pointer_cast<PipelineTask>(shared_from_this());
RETURN_IF_ERROR(_state_transition(PipelineTask::State::RUNNABLE));
+ // Under _wake_up_early, FINISHED/FINALIZED → RUNNABLE is a legal no-op
+ // (_state_transition returns OK but state stays unchanged). We must not
+ // resubmit a terminated task: finalize() clears _sink/_operators, and
+ // submit() → is_blockable() would dereference them → SIGSEGV.
+ if (_exec_state == State::FINISHED || _exec_state == State::FINALIZED) {
+ return Status::OK();
+ }
if (auto f = _fragment_context.lock(); f) {
RETURN_IF_ERROR(_state->get_query_ctx()->get_pipe_exec_scheduler()->submit(holder));
}
@@ -1057,12 +1064,6 @@ Status PipelineTask::wake_up(Dependency* dep, std::unique_lock<std::mutex>& /* d
}
Status PipelineTask::_state_transition(State new_state) {
- if (_exec_state != new_state) {
- _state_change_watcher.reset();
- _state_change_watcher.start();
- }
- _task_profile->add_info_string("TaskState", _to_string(new_state));
- _task_profile->add_info_string("BlockedByDependency", _blocked_dep ? _blocked_dep->name() : "");
const auto& table =
_wake_up_early ? WAKE_UP_EARLY_LEGAL_STATE_TRANSITION : LEGAL_STATE_TRANSITION;
if (!table[(int)new_state].contains(_exec_state)) {
@@ -1071,10 +1072,18 @@ Status PipelineTask::_state_transition(State new_state) {
_to_string(_exec_state), _to_string(new_state), debug_string());
}
// FINISHED/FINALIZED → RUNNABLE is legal under wake_up_early (delayed wake_up() arriving
- // after the task already terminated), but we must not actually move the state backwards.
+ // after the task already terminated), but we must not actually move the state backwards
+ // or update profile info (which would misleadingly show RUNNABLE for a terminated task).
bool need_move = !((_exec_state == State::FINISHED || _exec_state == State::FINALIZED) &&
new_state == State::RUNNABLE);
if (need_move) {
+ if (_exec_state != new_state) {
+ _state_change_watcher.reset();
+ _state_change_watcher.start();
+ }
+ _task_profile->add_info_string("TaskState", _to_string(new_state));
+ _task_profile->add_info_string("BlockedByDependency",
+ _blocked_dep ? _blocked_dep->name() : "");
_exec_state = new_state;
}
return Status::OK();
diff --git a/be/test/exec/pipeline/dummy_task_queue.h b/be/test/exec/pipeline/dummy_task_queue.h
index 87ff439be85..9cc3bebffe2 100644
--- a/be/test/exec/pipeline/dummy_task_queue.h
+++ b/be/test/exec/pipeline/dummy_task_queue.h
@@ -53,7 +53,10 @@ class MockTaskScheduler : public TaskScheduler {
public:
MockTaskScheduler() : TaskScheduler() { _task_queue = std::make_unique<DummyTaskQueue>(1); }
- Status submit(PipelineTaskSPtr task) override { return _task_queue->push_back(task); }
+ Status submit(PipelineTaskSPtr task) override {
+ _submit_count++;
+ return _task_queue->push_back(task);
+ }
Status start() override { return Status::OK(); }
@@ -63,7 +66,11 @@ public:
return {};
}
+ int submit_count() const { return _submit_count.load(); }
+ void reset_submit_count() { _submit_count.store(0); }
+
private:
std::unique_ptr<DummyTaskQueue> _task_queue;
+ std::atomic<int> _submit_count {0};
};
} // namespace doris
diff --git a/be/test/exec/pipeline/pipeline_task_test.cpp b/be/test/exec/pipeline/pipeline_task_test.cpp
index 8029270ea47..d773366a7f6 100644
--- a/be/test/exec/pipeline/pipeline_task_test.cpp
+++ b/be/test/exec/pipeline/pipeline_task_test.cpp
@@ -520,9 +520,11 @@ TEST_F(PipelineTaskTest, TEST_STATE_TRANSITION) {
task->_wake_up_early = false;
// Test that wake_up() succeeds when the task has already finished (delayed wake_up race).
- // _state_transition(RUNNABLE) is a no-op, and wake_up() should not re-submit the task.
+ // _state_transition(RUNNABLE) is a no-op, and wake_up() must NOT re-submit the task to the
+ // scheduler. Submitting a finalized task causes SIGSEGV in is_blockable() because _sink is null.
{
task->_wake_up_early = true;
+ _task_scheduler->reset_submit_count();
std::mutex mtx;
task->_exec_state = PipelineTask::State::FINISHED;
auto dep = std::make_shared<Dependency>(0, 0, "test_dep", true);
@@ -530,8 +532,10 @@ TEST_F(PipelineTaskTest, TEST_STATE_TRANSITION) {
std::unique_lock<std::mutex> lc(mtx);
EXPECT_TRUE(task->wake_up(dep.get(), lc).ok());
EXPECT_EQ(task->_exec_state, PipelineTask::State::FINISHED);
+ EXPECT_EQ(_task_scheduler->submit_count(), 0);
}
{
+ _task_scheduler->reset_submit_count();
std::mutex mtx;
task->_exec_state = PipelineTask::State::FINALIZED;
auto dep = std::make_shared<Dependency>(0, 0, "test_dep", true);
@@ -539,8 +543,21 @@ TEST_F(PipelineTaskTest, TEST_STATE_TRANSITION) {
std::unique_lock<std::mutex> lc(mtx);
EXPECT_TRUE(task->wake_up(dep.get(), lc).ok());
EXPECT_EQ(task->_exec_state, PipelineTask::State::FINALIZED);
+ EXPECT_EQ(_task_scheduler->submit_count(), 0);
task->_wake_up_early = false;
}
+ // Positive test: wake_up() on a BLOCKED task DOES submit to the scheduler.
+ {
+ _task_scheduler->reset_submit_count();
+ std::mutex mtx;
+ task->_exec_state = PipelineTask::State::BLOCKED;
+ auto dep = std::make_shared<Dependency>(0, 0, "test_dep", true);
+ task->_blocked_dep = dep.get();
+ std::unique_lock<std::mutex> lc(mtx);
+ EXPECT_TRUE(task->wake_up(dep.get(), lc).ok());
+ EXPECT_EQ(task->_exec_state, PipelineTask::State::RUNNABLE);
+ EXPECT_EQ(_task_scheduler->submit_count(), 1);
+ }
}
TEST_F(PipelineTaskTest, TEST_SINK_FINISHED) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org