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


##########
be/src/exec/pipeline/task_queue.cpp:
##########
@@ -48,10 +55,18 @@ PriorityTaskQueue::PriorityTaskQueue() : _closed(false) {
 }
 
 void PriorityTaskQueue::close() {
-    std::unique_lock<std::mutex> lock(_work_size_mutex);
-    _closed = true;
-    _wait_task.notify_all();
-    
DorisMetrics::instance()->pipeline_task_queue_size->increment(-_total_task_size);
+    std::vector<std::queue<PipelineTaskSPtr>> tasks_to_release;
+    {
+        std::unique_lock<std::mutex> lock(_work_size_mutex);
+        _closed = true;
+        const auto total_task_size = _total_task_size.exchange(0);
+        _wait_task.notify_all();
+        DorisMetrics::instance()->pipeline_task_queue_size->increment(
+                -static_cast<int64_t>(total_task_size));

Review Comment:
   The drain added here can still miss tasks that race with shutdown. 
`PriorityTaskQueue::push()` reads `_closed` before taking `_work_size_mutex`, 
then enqueues after it gets the mutex. A worker that is still finishing 
`PipelineTask::execute()` during `TaskScheduler::stop()` can enter `push()` 
before this method sets `_closed`, wait behind `close()`, and then enqueue 
after `take_all()` has already drained every sub-queue. That leaves a 
`PipelineTaskSPtr` retained after the only drain and also races the unlocked 
`_closed` read with the write here. Please move or repeat the `_closed` check 
under `_work_size_mutex` before adding to `_sub_queues` and incrementing 
`_total_task_size`, so close and submit are serialized.



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