fix: fix memory leak when cancel segcore task (#29431)

#29430

Signed-off-by: luzhang <luzhang@zilliz.com>
Co-authored-by: luzhang <luzhang@zilliz.com>
pull/29437/head
zhagnlu 2023-12-22 20:28:43 +08:00 committed by GitHub
parent dd9c61831d
commit 1cbe3cd5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 2 deletions

View File

@ -207,6 +207,11 @@ class Driver : public std::enable_shared_from_this<Driver> {
Init(std::unique_ptr<DriverContext> driver_ctx,
std::vector<std::unique_ptr<Operator>> operators);
void
CloseByTask() {
Close();
}
private:
Driver() = default;

View File

@ -129,6 +129,13 @@ Task::CreateDriversLocked(std::shared_ptr<Task>& self,
}
}
void
Task::Terminate(TaskState state) {
for (auto& driver : drivers_) {
driver->CloseByTask();
}
}
RowVectorPtr
Task::Next(ContinueFuture* future) {
// NOTE: Task::Next is single-threaded execution

View File

@ -149,8 +149,7 @@ class Task : public std::enable_shared_from_this<Task> {
}
void
Terminate(TaskState state) {
}
Terminate(TaskState state);
std::exception_ptr
error() const {
@ -167,6 +166,11 @@ class Task : public std::enable_shared_from_this<Task> {
num_finished_drivers_++;
}
void
RequestCancel() {
Terminate(TaskState::kCanceled);
}
private:
std::string uuid_;

View File

@ -116,6 +116,7 @@ ExecPlanNodeVisitor::ExecuteExprNodeInternal(
if (cache_offset_vec->size() == 0) {
auto active_count = segment->get_active_count(timestamp_);
bitset_holder.resize(active_count);
task->RequestCancel();
break;
}
auto cache_offset_vec_ptr =