[bugfix](becore) has to use value to capture lambda value to avoid core during callback (#32132)

Co-authored-by: yiguolei <yiguolei@gmail.com>
This commit is contained in:
yiguolei
2024-03-12 21:17:07 +08:00
committed by yiguolei
parent 84af8e0a53
commit 5da7cd0fba

View File

@ -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<PTabletWriterAddBlockResult>::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;
}