diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index b6ce6e32592c97..272e0b32601d0b 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -175,6 +175,24 @@ uint32_t InteractionModelEngine::GetNumActiveWriteHandlers() const return numActive; } +void InteractionModelEngine::CloseTransactionsFromFabricIndex(FabricIndex aFabricIndex) +{ + // + // Walk through all existing subscriptions and shut down those whose subscriber matches + // that which just came in. + // + mReadHandlers.ForEachActiveObject([this, aFabricIndex](ReadHandler * handler) { + if (handler->GetAccessingFabricIndex() == aFabricIndex) + { + ChipLogProgress(InteractionModel, "Deleting expired ReadHandler for NodeId: " ChipLogFormatX64 ", FabricIndex: %u", + ChipLogValueX64(handler->GetInitiatorNodeId()), aFabricIndex); + mReadHandlers.ReleaseObject(handler); + } + + return Loop::Continue; + }); +} + CHIP_ERROR InteractionModelEngine::ShutdownSubscription(uint64_t aSubscriptionId) { for (auto * readClient = mpActiveReadClientList; readClient != nullptr; readClient = readClient->GetNextClient()) diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index 2782a3555fa81c..f89ada218da0ec 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -110,6 +110,12 @@ class InteractionModelEngine : public Messaging::ExchangeDelegate, public Comman */ CHIP_ERROR ShutdownSubscriptions(FabricIndex aFabricIndex, NodeId aPeerNodeId); + /** + * Expire active transactions and release related objects for the given fabric index. + * This is used for releasing transactions that won't be closed when a fabric is removed. + */ + void CloseTransactionsFromFabricIndex(FabricIndex aFabricIndex); + uint32_t GetNumActiveReadHandlers() const; uint32_t GetNumActiveReadHandlers(ReadHandler::InteractionType type) const; diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index 3d6e4156410ac9..40c2f6359dbb5f 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -356,6 +356,7 @@ class FabricCleanupExchangeDelegate : public chip::Messaging::ExchangeDelegate void OnExchangeClosing(chip::Messaging::ExchangeContext * ec) override { FabricIndex currentFabricIndex = ec->GetSessionHandle()->GetFabricIndex(); + InteractionModelEngine::GetInstance()->CloseTransactionsFromFabricIndex(currentFabricIndex); ec->GetExchangeMgr()->GetSessionManager()->ExpireAllPairingsForFabric(currentFabricIndex); } }; @@ -414,6 +415,7 @@ bool emberAfOperationalCredentialsClusterRemoveFabricCallback(app::CommandHandle } else { + InteractionModelEngine::GetInstance()->CloseTransactionsFromFabricIndex(fabricBeingRemoved); ec->GetExchangeMgr()->GetSessionManager()->ExpireAllPairingsForFabric(fabricBeingRemoved); } }