Merged
fix(queue_schedule): 捕获动态调度请求构建时的内存分配异常 #6194
fix(queue_schedule): 捕获动态调度请求构建时的内存分配异常 #6194
Merged
zhaowenruiAdd on 17 days ago
Total: 2 files changed+43-3
@@ -8,6 +8,7 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10 10 
11+#include <new>
11#include "bind_relation.h"12#include "bind_relation.h"
12#include "common/bqs_log.h"13#include "common/bqs_log.h"
13#include "fsm/try_push_state.h"14#include "fsm/try_push_state.h"
@@ -72,9 +73,14 @@ FsmStatus TryPushState::PreProcess(Entity& entity)
72 73 
73 std::shared_ptr<DynamicSchedMgr::RequestInfo> dynamicRequest = nullptr;74 std::shared_ptr<DynamicSchedMgr::RequestInfo> dynamicRequest = nullptr;
74 uint32_t schedCfgKey = 0U;75 uint32_t schedCfgKey = 0U;
75- for (auto reprocessEntity : reprocessDstEntities) {76+ try {
76- dataObj->AddRecvEntity(reprocessEntity);77+ for (auto reprocessEntity : reprocessDstEntities) {
77- reprocessEntity->ReprocessInTryPush(entity, dynamicRequest, schedCfgKey);78+ dataObj->AddRecvEntity(reprocessEntity);
79+ reprocessEntity->ReprocessInTryPush(entity, dynamicRequest, schedCfgKey);
80+ }
81+ } catch (const std::bad_alloc& error) {
82+ DGW_LOG_ERROR("Fail to build dynamic request for entity:%u, error:%s.", entity.GetId(), error.what());
83+ return FsmStatus::FSM_FAILED;
78 }84 }
79 const auto sendRet = SendRequestForDynamicGroup(dynamicRequest, schedCfgKey, entity);85 const auto sendRet = SendRequestForDynamicGroup(dynamicRequest, schedCfgKey, entity);
80 if (sendRet != FsmStatus::FSM_SUCCESS) {86 if (sendRet != FsmStatus::FSM_SUCCESS) {
@@ -8,6 +8,7 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10#include <atomic>10#include <atomic>
11+#include <new>
11#include <unordered_set>12#include <unordered_set>
12#include "gtest/gtest.h"13#include "gtest/gtest.h"
13#include "mockcpp/mockcpp.hpp"14#include "mockcpp/mockcpp.hpp"
@@ -16,6 +17,7 @@
16#define protected public17#define protected public
17#include "hccl/hccl_types_in.h"18#include "hccl/hccl_types_in.h"
18#include "entity_manager.h"19#include "entity_manager.h"
20+#include "group_entity.h"
19#include "server/bind_relation.h"21#include "server/bind_relation.h"
20#include "server/queue_schedule.h"22#include "server/queue_schedule.h"
21#include "server/queue_manager.h"23#include "server/queue_manager.h"
@@ -3495,4 +3497,36 @@ TEST_F(QueueScheduleUTest, F2NF_with_halEschedWaitEventFail)
3495 3497 
3496 controlThread.join();3498 controlThread.join();
3497}3499}
3500+TEST_F(QueueScheduleUTest, TryPushCatchesDynamicRequestAllocationFailure)
3501+{
3502+ struct ThrowingGroup : dgw::GroupEntity {
3503+ using GroupEntity::GroupEntity;
3504+ void ReprocessInTryPush(const dgw::Entity&, dgw::DynamicRequestPtr&, uint32_t&) override
3505+ {
3506+ throw std::bad_alloc();
3507+ }
3508+ };
3509+ dgw::EntityMaterial material = {};
3510+ material.eType = dgw::EntityType::ENTITY_GROUP;
3511+ material.groupPolicy = bqs::GroupPolicy::DYNAMIC;
3512+ material.id = 4001U;
3513+ dgw::GroupEntity source(material, 0U);
3514+ material.id = 4002U;
3515+ auto destination = std::make_shared<ThrowingGroup>(material, 0U);
3516+ OptionalArg args = {};
3517+ args.eType = dgw::EntityType::ENTITY_GROUP;
3518+ EntityInfo srcInfo(4001U, 0U, &args);
3519+ EntityInfo dstInfo(4002U, 0U, &args);
3520+ dstInfo.SetEntity(destination);
3521+ auto& relations = BindRelation::GetInstance().srcToDstRelation_;
3522+ relations[srcInfo].insert(dstInfo);
3523+ MOCKER_CPP(&dgw::DynamicSchedMgr::SendRequest).expects(never());
3524+ 
3525+ dgw::TryPushState state;
3526+ EXPECT_EQ(state.PreProcess(source), dgw::FsmStatus::FSM_FAILED);
3527+ EXPECT_TRUE(source.GetSendDataObjs().empty());
3528+ EXPECT_FALSE(source.GetWaitDecisionState());
3529+ relations.erase(srcInfo);
3530+}
3531+ 
3498} // namespace bqs3532} // namespace bqs