From e47d1fccf59c8eff57eb7fb823287f89bd5b0adf Mon Sep 17 00:00:00 2001 From: yiguolei <676222867@qq.com> Date: Sat, 29 Jul 2023 22:41:46 +0800 Subject: [PATCH] [bugfix](be core) fragment executor's destruct method should be called before query context (#22362) fragment executor's destruct method will call close, it depends on query context's object pool, because many object is put in query context's object pool such as runtime filter. It should be deleted before query context. Or there will be heap use after free error. It is fixed in #17675, but Do not know why not in master. So 1.2-lts does not have this problem. --------- Co-authored-by: yiguolei --- be/src/runtime/fragment_mgr.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/be/src/runtime/fragment_mgr.cpp b/be/src/runtime/fragment_mgr.cpp index bce4db795d..9b184f6c33 100644 --- a/be/src/runtime/fragment_mgr.cpp +++ b/be/src/runtime/fragment_mgr.cpp @@ -183,6 +183,11 @@ private: int _backend_num; TNetworkAddress _coord_addr; + // This context is shared by all fragments of this host in a query. + // _query_ctx should be the last one to be destructed, because _executor's + // destruct method will call close and it will depend on query context, + // for example runtime profile. + std::shared_ptr _query_ctx; PlanFragmentExecutor _executor; vectorized::VecDateTimeValue _start_time; @@ -196,9 +201,6 @@ private: int _timeout_second; std::atomic _cancelled {false}; - // This context is shared by all fragments of this host in a query - std::shared_ptr _query_ctx; - std::shared_ptr _merge_controller_handler; // If set the true, this plan fragment will be executed only after FE send execution start rpc. @@ -213,12 +215,12 @@ FragmentExecState::FragmentExecState(const TUniqueId& query_id, : _query_id(query_id), _fragment_instance_id(fragment_instance_id), _backend_num(backend_num), + _query_ctx(std::move(query_ctx)), _executor(exec_env, std::bind(std::mem_fn(&FragmentExecState::coordinator_callback), this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)), _set_rsc_info(false), _timeout_second(-1), - _query_ctx(std::move(query_ctx)), _report_status_cb_impl(report_status_cb_impl) { _start_time = vectorized::VecDateTimeValue::local_time(); _coord_addr = _query_ctx->coord_addr;