Skip to content

Commit

Permalink
[bugfix](becore) has to use value to capture lambda value to avoid co…
Browse files Browse the repository at this point in the history
…re during callback (#32132)

Co-authored-by: yiguolei <[email protected]>
  • Loading branch information
yiguolei and Doris-Extras authored Mar 12, 2024
1 parent f7776bb commit 4c775a6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions be/src/vec/sink/writer/vtablet_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,20 @@ 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;
}
_add_block_failed_callback(is_last_rpc);
});

_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;
}
Expand Down

0 comments on commit 4c775a6

Please sign in to comment.