Skip to content

Commit

Permalink
[IM] Abort read/subscribe transactions when deleting related fabric (#…
Browse files Browse the repository at this point in the history
…15901)

* [IM] Abort read/subscribe transactions when deleting related fabric

* Update src/app/InteractionModelEngine.cpp

Co-authored-by: Andrei Litvin <[email protected]>

* Update InteractionModelEngine.cpp

Co-authored-by: Justin Wood <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Nov 14, 2023
1 parent ddeea3c commit 3312305
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -414,6 +415,7 @@ bool emberAfOperationalCredentialsClusterRemoveFabricCallback(app::CommandHandle
}
else
{
InteractionModelEngine::GetInstance()->CloseTransactionsFromFabricIndex(fabricBeingRemoved);
ec->GetExchangeMgr()->GetSessionManager()->ExpireAllPairingsForFabric(fabricBeingRemoved);
}
}
Expand Down

0 comments on commit 3312305

Please sign in to comment.