Merged
fix(queue_schedule): 捕获动态调度请求构建时的内存分配异常 #6194
fix(queue_schedule): 捕获动态调度请求构建时的内存分配异常 #6194
Merged
zhaowenruiAdd on 17 days ago
zhaowenrui
zhaowenruiCollaborators
17 days ago

Pull Request

描述

动态组构建调度请求时,make_shared 或 vector 扩容抛出的 std::bad_alloc 原本会沿调用链向外传播。

在 TryPushState::PreProcess 的动态组请求构建循环外增加 try/catch,捕获 std::bad_alloc、记录错误并返回已有的 FSM_FAILED。失败时不进入发送请求、设置等待决策状态或挂入发送列表的路径,局部请求与 DataObj 随返回自动释放。保持 ReprocessInTryPush 接口及各实体实现不变。

只修改一个业务文件,新增一个回归用例,验证调用抛出 bad_alloc 时返回失败、不下发请求且不遗留等待状态或发送对象;已有动态组成功路径用例继续覆盖正常行为。

变更类型

关联的Issue

#1341

如何测试

  1. 使用现有生成规则重新编译队列调度 UT:
    gmake -C build -f tests/ut/queue_schedule/ut/CMakeFiles/queue_schedule_main_ut.dir/build.make tests/ut/queue_schedule/ut/CMakeFiles/queue_schedule_main_ut.dir/build -j4
    
  2. 运行相关测试:
    build/tests/ut/queue_schedule/ut/queue_schedule_main_ut --gtest_filter='EntityUTest.*:QueueScheduleUTest.*'
    
    重新编译后,2 个相关套件共 153 个用例全部通过。
  3. pre-commit 的 clang-format 与 OAT 合规检查通过。

核对清单

其他信息

本次仅保护 TryPushState 中的动态组请求构建循环,未扩展为整个事件循环的内存不足恢复机制。采用已有 CMake 目标构建规则完成 Host UT 验证,未运行真实设备测试。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zhaowenrui's contribution.)
zhaowenruizhaowenruiCollaborators
17 days ago Created pull request, commit 0dcf0805
zhaowenruizhaowenruiCollaborators
17 days ago Associated issue: [Bug-Report|缺陷反馈]: queue_schedule 异常路径资源清理、参数校验及诊断日志问题
atomgit-bot
atomgit-bot
17 days ago Comments:

变更摘要

本次变更针对动态组(GroupPolicy::DYNAMIC)在构建调度请求时可能抛出 std::bad_alloc 的问题:在 GroupEntity::ReprocessInTryPush 中对 std::make_shared 及 decisions/dsts 的 emplace_back 扩容进行异常捕获,异常发生时清空 dynamicRequest、记录错误日志并返回 FSM_FAILED。为此将 Entity::ReprocessInTryPush 虚接口及 GroupEntity 实现的返回类型由 void 调整为 FsmStatus,TryPushState::PreProcess 据此在失败时提前结束处理,避免发送部分请求或进入等待决策状态,复用既有 FSM_FAILED 处理路径。

主要改动

  • ReprocessInTryPush 接口返回值调整:Entity 与 GroupEntity 中的 ReprocessInTryPush 由 void 改为返回 FsmStatus,基类默认实现返回 FSM_SUCCESS,非动态组策略同样返回成功,使调用方能够感知失败。
  • 内存分配异常捕获:GroupEntity::ReprocessInTryPush 引入 <new> 并用 try/catch (const std::bad_alloc&) 包裹请求对象创建与目的组追加逻辑,捕获后执行 dynamicRequest.reset()、输出 DGW_LOG_ERROR 并返回 FSM_FAILED,不再依赖原 DGW_CHECK_RET_VOID 空指针校验。
  • TryPushState::PreProcess 失败短路:在遍历 reprocessDstEntities 时检查 ReprocessInTryPush 的返回状态,非 FSM_SUCCESS 时直接返回该状态,从而跳过 SendRequestForDynamicGroup 及后续状态设置。
  • 回归测试覆盖分配失败场景:entity_utest.cpp 新增 ExhaustChildAddressSpace 辅助函数(通过 RLIMIT_AS 限制并耗尽分配器存储),在子进程内验证请求对象分配失败与 dsts 扩容失败均返回 FSM_FAILED 且 dynamicRequest 被清空。
  • 上层行为测试:queue_schedule_utest.cpp 新增用例,通过桩替换 GroupEntity::ReprocessInTryPush 返回 FSM_FAILED,验证 ChangeState(FSM_TRY_PUSH_STATE) 返回失败、SendRequest 未被调用、发送数据列表为空且未进入等待决策状态。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
17 days ago Comments:

代码审查

✅ 未发现问题


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
17 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
17 days ago Comments:

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
src/queue_schedule ✅ ZhaiPeiChao, LiWei79 (2/2) ✅ ZhaiPeiChao (1/1)
tests/ut/queue_schedule ✅ ZhaiPeiChao, LiWei79 (2/2) ✅ ZhaiPeiChao (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

zhaowenrui666, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
17 days ago Set wangtao43,zhangpengpeng8,yanmingxiang,LiWei79,ZhaiPeiChao,Reyn52166,ykl999,houyanbao,tingwood as approver
7 event messages are collapsed here。 See more
zhaowenruizhaowenruiCollaborators
17 days ago Modify description of pull request
zhaowenrui
zhaowenruiCollaborators
17 days ago Comments:

compile

likedislike
zhaowenruizhaowenruiCollaborators
17 days ago Pre merge succeeded (commit_id: 7ae97e6ba47ffb7ca5737f698bd2c1b1fc58b78d)
CANN-robot
CANN-robotCollaborators
17 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
17 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
17 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
17 days ago Added label: ci-pipeline-passed
ZhaiPeiChao
ZhaiPeiChaoCollaborators
17 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
17 days ago Added label: approved
DevLeev
DevLeevCollaborators
17 days ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
17 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
17 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
17 days ago Merged pull request