From 4c775a6a3c920e3fb56f71d81c8f9f39df9d205a Mon Sep 17 00:00:00 2001 From: yiguolei <676222867@qq.com> Date: Tue, 12 Mar 2024 21:17:07 +0800 Subject: [PATCH] [bugfix](becore) has to use value to capture lambda value to avoid core during callback (#32132) Co-authored-by: yiguolei --- be/src/vec/sink/writer/vtablet_writer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/be/src/vec/sink/writer/vtablet_writer.cpp b/be/src/vec/sink/writer/vtablet_writer.cpp index 1e888f2460e60c..97e8ffe1e77fd2 100644 --- a/be/src/vec/sink/writer/vtablet_writer.cpp +++ b/be/src/vec/sink/writer/vtablet_writer.cpp @@ -357,9 +357,10 @@ Status VNodeChannel::init(RuntimeState* state) { _cur_add_block_request->set_eos(false); // add block closure + // Has to using value to capture _task_exec_ctx because tablet writer may destroyed during callback. _send_block_callback = WriteBlockCallback::create_shared(); - _send_block_callback->addFailedHandler([this](bool is_last_rpc) { - auto ctx_lock = _task_exec_ctx.lock(); + _send_block_callback->addFailedHandler([&, task_exec_ctx = _task_exec_ctx](bool is_last_rpc) { + auto ctx_lock = task_exec_ctx.lock(); if (ctx_lock == nullptr) { return; } @@ -367,8 +368,9 @@ Status VNodeChannel::init(RuntimeState* state) { }); _send_block_callback->addSuccessHandler( - [this](const PTabletWriterAddBlockResult& result, bool is_last_rpc) { - auto ctx_lock = _task_exec_ctx.lock(); + [&, task_exec_ctx = _task_exec_ctx](const PTabletWriterAddBlockResult& result, + bool is_last_rpc) { + auto ctx_lock = task_exec_ctx.lock(); if (ctx_lock == nullptr) { return; }