Pull Request已成功合入, 合并人@CANN-robot
(感谢 lining23666 的贡献)变更摘要
本 PR 修复 dflow/runner/session/dflow_api.cc 中 DFlowInitialize 与 DFlowFinalize 的资源管理与生命周期问题。核心改动是将完整清理逻辑提取到匿名命名空间中的 DFlowFinalizeImpl() 函数(包含 SessionManager Finalize、malloc_trim、ge::DFlowFinalizeInner()、aclFinalize() 及标志位重置),使初始化失败时可复用同一清理路径实现自动回滚;同时在 DFlowInitialize 入口加锁解决并发竞态,并移除 DFlowFinalize 中对 g_dflow_ge_initialized 的检查,改为无条件幂等清理。
主要改动
- 提取
DFlowFinalizeImpl()统一清理逻辑: 将原先分散在DFlowFinalize中的 SessionManager Finalize、malloc_trim(0)、DFlowFinalizeInner()、aclFinalize()与acl_initialized/acl_owned_by_dflow标志重置集中到匿名命名空间的DFlowFinalizeImpl(),供初始化失败回滚与正常 Finalize 共用。 DFlowInitialize失败自动回滚: 入口新增std::lock_guard<std::mutex> lock(g_dflow_ge_release_mutex)防止并发覆盖g_dflow_session_manager导致泄漏;当 SessionManager 创建失败或ge::DFlowInitializeInner(options)返回非 SUCCESS 时调用DFlowFinalizeImpl()清理已初始化的 ACL、SessionManager 等资源,避免资源泄漏。DFlowFinalize改为无条件幂等清理: 删除对g_dflow_ge_initialized的检查(该标志在初始化失败后为 false 会跳过清理),直接加锁调用DFlowFinalizeImpl(),保证重复或初始化失败后的 Finalize 也能正确执行清理。- 修正
aclFinalize调用顺序: 将aclFinalize()从原先DFlowFinalize开头的提前执行,移动到DFlowFinalizeImpl()末尾、在 SessionManager/PNE 清理之后执行,避免 SessionManager Finalize 触发GeSession析构调用DestroyRtContexts时 ACL 已被释放导致的 use-after-free。


Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/ge | ✅ 张德鹏, xchu42, stevenaw0 (3/2) | ✅ 张德鹏 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
lining23666, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [09bb1793ae7546729262abb01e2655be][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_ARM_compiler | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_ARM_executor | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_ARM_dflow | ✅ SUCCESS | >>>>> | >>>>> |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_A900_npupool | ✅ SUCCESS | >>>>> |
[2026-08-20 19:13:02] CI执行结束


流水线任务触发成功
任务链接 [6a183642c85a4fb4bd0035f157d69910][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_X86_compiler | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_executor | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_dflow | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_dflow | ✅ SUCCESS | ||
| UT_Test_ge_common | ✅ SUCCESS | ||
| UT_Test_parser | ✅ SUCCESS | ||
| UT_Test_python | ✅ SUCCESS | >>>>> | |
| UT_Test_rt | ✅ SUCCESS | ||
| UT_Test_acl | ✅ SUCCESS | ||
| UT_Test_autofuse | ✅ SUCCESS | ||
| UT_Test_executor | ✅ SUCCESS | ||
| UT_Test_autofuse_ascendc_api | ✅ SUCCESS | ||
| ST_Test_dflow | ✅ SUCCESS | ||
| ST_Test_ge_common | ✅ SUCCESS | ||
| ST_Test_parser | ✅ SUCCESS | ||
| ST_Test_python | ✅ SUCCESS | >>>>> | |
| ST_Test_rt | ✅ SUCCESS | ||
| ST_Test_autofuse | ✅ SUCCESS | ||
| ST_Test_executor | ✅ SUCCESS | ||
| ST_Test_hetero | ✅ SUCCESS | ||
| ST_Test_autofuse_ascendc_api | ✅ SUCCESS | ||
| ST_Test_autofuse_e2e | ✅ SUCCESS | ||
| UT_Test_fe | ✅ SUCCESS | ||
| UT_Test_tefusion | ✅ SUCCESS | ||
| ST_Test_fe | ✅ SUCCESS | ||
| ST_Test_tefusion | ✅ SUCCESS | ||
| ST_Test_ge_common_atc | ✅ SUCCESS | ||
| UT_Test_Report_graphengine | ✅ SUCCESS | >>>>> | |
| UT_Test_Report_ge_executor_c | ✅ SUCCESS | >>>>> | |
| UT_Test_Report_ge_autofuse | ✅ SUCCESS | >>>>> | |
| ST_Test_Report_graphengine | ✅ SUCCESS | >>>>> | |
| ST_Test_Report_ge_executor_c | ✅ SUCCESS | >>>>> | |
| ST_Test_Report_ge_autofuse | ✅ SUCCESS | >>>>> | |
| UT_Test_Report_fe | ✅ SUCCESS | >>>>> | |
| ST_Test_Report_fe | ✅ SUCCESS | >>>>> |
[2026-08-20 19:29:11] CI执行结束


流水线任务触发成功
任务链接 [912debde3d244db3a6a595361dbfb43c][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck_Pr | ✅ SUCCESS | ||
| antipoison | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| codecheck_dt | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS |
[2026-08-20 19:10:44] CI执行结束


/lgtm


/lgtm


Pull Request
描述
修复 DFlowInitialize 和 DFlowFinalize 中存在的 4 个问题:
修复方案
变更类型
关联的Issue
如何测试
核对清单
其他信息
测试结果:10 个相关 UT 全部通过,包括验证回滚路径的 DFlowInitialize_pne_init_failed、验证 ACL 重复初始化兼容的 DFlowInitialize_acl_repeat_init、验证 ACL 失败的 DFlowInitialize_acl_init_failed。